Screen capture - elements to images

156 views
Skip to first unread message

Vince Scafaria

unread,
May 25, 2023, 5:30:02 PM5/25/23
to Chromium Extensions
I see the documentation for screen capture and am unclear if it (or some other means) can accomplish my use case:

I would like to help the user capture posts from their social stream to image files. For example, if the page has 50 DIVs with a particular class, I'd like to capture a wysywig rendering into 50 images, e.g. saved to IndexedDB. I am not looking to do a full window screen grab, nor would I want 50 prompts (although a single prompt at the beginning of the operation and remembered from then on, or for duration of that session, for that site would be fine). 

I see JS libraries like html-to-image. But I'm reluctant to add such a large quantity of external javascript, preferring to understand and control all the JS included in the extension. With great power comes great responsibility, so a browser/extension API approach seems preferable. 

If this is not possible today, I wonder if you might consider it for the future. Use cases include preservation of one's social network data, online research (capturing not only text, but also how it's rendered), etc. Thanks! 

Patrick Kettner

unread,
May 26, 2023, 3:06:32 PM5/26/23
to Vince Scafaria, Chromium Extensions
Hi vince!
FWIW, html-to-image is only about 13kb. It has no sub dependencies, and is treeshakable, so it will ship a pretty small amount of code overall. That being said, if you wanted to do it today, with what we have in extensions, one option that comes to mind is the `Page.captureScreenshot` portion of `chrome.debugger`. I don't have a specific code sample for it, but it would likely look like 

```
const screenshot = await chrome.debugger.sendCommand(debuggee, "Page.captureScreenshot", { 
  format: "jpeg",
  quality: 80,
  clip: { x: 0, y: 0, width: screen.width, height: screen.height, scale: 1},
  fromSurface: true,
  captureBeyondViewport: true,
  optimizeForSpeed: false
})
```

`debuggee` would be a tabId that you can get from chrome.tabs.

--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/1a9085c2-4b22-4960-9631-fd99a90654a6n%40chromium.org.

Vince Scafaria

unread,
May 27, 2023, 5:39:27 PM5/27/23
to Chromium Extensions, Patrick Kettner, Chromium Extensions, Vince Scafaria
Looks very promising. Thank you!

Simeon Vincent

unread,
Jun 1, 2023, 3:36:33 PM6/1/23
to Vince Scafaria, Chromium Extensions, Patrick Kettner
As some more general context for this, I wanted to share two quick notes. First, a Chrome engineer is actively working on a draft spec for Element Capture. This is a web platform capability, but if/when it lands it will also be available to extensions. Second, the WECG is aware that there are challenges around using capture APIs for both capturing content rendered inside an extension's offscreen document and when using an offscreen document to capture the content of other tabs. We're very early in discussing how best to address this, but it's on our radar.

Simeon - @dotproto


Patrick Kettner

unread,
Jun 2, 2023, 9:45:59 AM6/2/23
to Simeon Vincent, Chromium Extensions, Vince Scafaria
Thanks Simeon!
Are there links to any of the discussions? If not, is there a good place or call for folks to go to give feedback or learn more?
Reply all
Reply to author
Forward
0 new messages