drawWindow in WebExtension

Hi,

T.l.d.r. When can I use CanvasRenderingContext2D.drawWindow() in my WebExtension?

I’ve made a WebExtension but found out there’s no access to CanvasRenderingContext2D.drawWindow().
Firefox has the awesome ability to take a single screenshot of the entire document. Also what’s outside of the viewport, and at very high resolution too when specifying a custom scale using this method:
https://dxr.mozilla.org/mozilla-central/source/b2g/components/Screenshot.jsm

The only API that’s currently available for WebExtensions is tabs.captureVisibleTab().
But this good enough for me as it would involve scrolling and stitching individual captures.

Would it be an idea to expose the Screenshot functionality (like drawWindow()) through a tabs API?
I don’t think Google Chrome will implement this soon. As far as I’m aware that browser doesn’t have the ability to take full document captures at all.

Thanks in advance.

This should work in Firefox 54, if I’m reading https://bugzilla.mozilla.org/show_bug.cgi?id=1310318 correctly.

1 Like

That’s great! I can’t wait :slight_smile: thanks for replying.

I’m using now Firefox 56, and 57 developer edition, but when I create a 2d context, drawWindow() function is still not available. The Bugzilla post mentioned by Boris above says something about permissions (“access to canvas drawWindow() with permission…”), but the permission for drawWindow() cannot be found anywhere.

I’m trying to create this context in an extension (tried both background.js and in a script injected into a page), the only result I get is “drawWindow is undefined”. Looking under a debugger at proto:CanvasRenderingContext2DPrototype of a created context object, the only functions starting with ‘d’ are drawFocusIfNeeded() and drawImage()


UPDATE some minutes later:
It works now, all I needed to do was to add “<all_urls>” permission to the manifest.json of my extension. Thanks!