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

(Juraj Masiar) #1

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 :slight_smile:

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

This is my button click:

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 should solve this issue (because you can specify target tab id) but it seems to be broken in Android:

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( 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').

browser.tabs.captureTab actually doesn’t exists on Android :smiley:

Still the original problem remains.


(Juraj Masiar) #2

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

if (! await browser.tabs.update(, {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.