# Firefox for Android - taking screenshot of page using button in Popup

**URL:** <https://discourse.mozilla.org/t/firefox-for-android-taking-screenshot-of-page-using-button-in-popup/37196>\
**Category:** Development\
**Created:** [March 20, 2019, 9:27am UTC](https://discourse.mozilla.org/t/firefox-for-android-taking-screenshot-of-page-using-button-in-popup/37196 "2019-03-20T09:27:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![juraj.masiar](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/juraj.masiar/32/30587_2.png) [@juraj.masiar](https://discourse.mozilla.org/u/juraj.masiar)\
**Post date:** [March 20, 2019, 9:27am UTC](https://discourse.mozilla.org/t/firefox-for-android-taking-screenshot-of-page-using-button-in-popup/37196/1 "2019-03-20T09:27:35Z")

</div>

I’m now porting one of my add-ons for Android and I have a problem with one of the features - taking screenshot of current page using a button in the Popup.

Since Popups in Android are opened as normal pages, when I click the button in the Popup, it will take screenshot of the Popup 🙂

**Is there some nice way to wait for the Popup to be closed?**

This is my button click:

```javascript
e => {browser.runtime.sendMessage({type: 'add_current'}); window.close()};

```

Then background will handle the screenshot capture - and here I would like to wait for the pop-up to be closed and the previous page to be rendered.

NOTE that [caputreTab API](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/captureTab) should solve this issue (because you can specify target tab id) ~~but it seems to be broken in Android: [https://bugzilla.mozilla.org/show\_bug.cgi?id=1536384](https://bugzilla.mozilla.org/show_bug.cgi?id=1536384)~~

**EDIT:**  
One bug here - seems like Popup in Android cannot be closed with `window.close()` and one have to use `browser.tabs.getCurrent().then(tab => browser.tabs.remove(tab.id))` to close it - this however won’t work in desktop version so you need to detect Android first with something like this `browser.runtime.getPlatformInfo().then(({os}) => os === 'android')`.

**EDIT 2:**  
`browser.tabs.captureTab` actually doesn’t exists on Android 😃

Still the original problem remains.

---

<div class="post-metadata">

**Author:** ![juraj.masiar](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/juraj.masiar/32/30587_2.png) [@juraj.masiar](https://discourse.mozilla.org/u/juraj.masiar)\
**Post date:** [March 20, 2019, 12:14pm UTC](https://discourse.mozilla.org/t/firefox-for-android-taking-screenshot-of-page-using-button-in-popup/37196/2 "2019-03-20T12:14:34Z")

</div>

So it looks like all I needed was a one line of code in my background script:

```javascript
if (!tab.active) await browser.tabs.update(tab.id, {active: true});

```

This will activate the tab that needs to be focused and waits until it’s focused. The popup will be closed asynchronously in the meantime.
