Any way to get a screenshot of non-active tabs?

So I see tabs.captureVisibleTab() which allows for capturing active tabs, but is there any way to get screenshots of non-active ones? What I’d like to be able to do is create a UI with all the tabs shown in a grid, with a small screenshot of each as a preview, similar to what the old Tab Groups UI looked like.

You can try to inject a content script in your tab to create a canvas, use context2d.drawWindow() to capture the content and send the data back to your add-on background.

I’m not 100% sure drawWindow() will work well if the tab is not the active but it’s worth the try.

Hmm, so it won’t work for tabs I can’t inject scripts into (which I guess is an acceptable compromise), but otherwise this seems to do exactly what I want it to do. Thanks!

Maybe you can also consider a non-active tab is very likely to have been active at some point and you were able to use tabs.captureVisibleTab(). If you do a good job saving thumbnails whenever you can do it and caching those images, that may work.

You should check whether tabs.captureVisibleTab() works on Firefox admin pages like about:addons or about:config as if it as been implemented the way i suggested, it may not work for the reason you mentioned.

Hmm, to be honest, the set of tabs I can’t inject stuff into is probably small enough in general that it probably wouldn’t even matter if they were missing screenshots. I might look into that kind of strategy as a backup mechanism once I get the main bits in place, though.

Apologize for bumping a 2 1/2 year old thread but, I too was wondering how to capture a non-visable tab.

@aroskuski I’d be interested in hearing what you settled on if you’re still around lol.

@mig do you think caching captureVisableTab() when it is active is still the best option, 2 years later? Or have things progressed any from then?

I was looking at html2canvas before I found this thread.

Too bad there isn’t a parameter to pass in a tab ID and this so we can capture a non-visible tab. Of course, I have no idea how the captureVisableTab() itself works or how capturing browser screenshots functions under the hood works either.


@aroskuski reading the OP after the fact, this is the same extension I just finished building, except I’m currently using tab favicons, which is fine but, would be cool to have screenshots instead.

(great minds)

Firefox has a seemingly non-standard method that can screenshot non-selected tabs, if your extension has “all URLs” permission (since Firefox 59, so not back when this thread was started):