As chaals noted in the GitHub issue, this raises some privacy and security issues, so this definitely needs to be guarded by security measures.
Regarding this, what should happen with iframes within the document, which don’t fall under the same origin policy? What if the user wants to black parts of the screenshot (for privacy reasons) before the data is made available through the API.
Besides the security implications, I think the currently suggested API is pretty restricted in what it can do. In my opinion, it should also allow to make a screenshot of an arbitrary rect of the document (making full-page screenshots possible) and provide options to define the output format and other options similar to the
So, I’d imagine something like this:
ImageData = window.screenshot(HTMLElement element or DOMRect rect, optional DOMString type, optional any quality)
Or two separate functions for elements and rects. The
toBlob() method of the
HTMLCanvasElement interface could be moved to the
HTMLElement interface and another
toBlob() method could be added allowing to take screenshots of rects:
void window.toBlob(BlobCallback callback, DOMRect rect, optional DOMString type, optional any quality)