OffscreenDocument API has limited chrome.* API?

769 views
Skip to first unread message

Juraj M.

unread,
Jan 1, 2023, 9:06:58 AM1/1/23
to Chromium Extensions
I would like to use this new API to load an `iframe` and take a screenshot of it.
But there is only "runtime" namespace available???

Screenshot 2023-01-01 150206.png

How do I do ... stuff, without all the API? Like getting its windowId or tabId.

Maybe I need to use a better "Reason", but the API doesn't really say what those things do:
https://developer.chrome.com/docs/extensions/reference/offscreen/#type-Reason

I'm super confused about this API... Why limit it this way?

wOxxOm

unread,
Jan 2, 2023, 3:29:22 AM1/2/23
to Chromium Extensions, juraj....@gmail.com
It's intentionally limited, otherwise everyone will just use this document instead of the service worker and everyone will understand (not just 1% of savvy developers) that Chromium team has made a big mistake switching to a service worker, the least suitable JS environment for an extension background script due to the multiple artificial limits that make sense only for serving remote web pages.

The solution is to use `chrome` API in the service worker i.e. the offscreen document would send a message: 
  • chrome.runtime.sendMessage
  • BroadcastChannel
  • direct via (await navigator.serviceWorker.ready).active.postMessage(123) in the caller and self.onmessage = async e => { ........; e.source.postMessage(456) } in the SW.
Web messaging (BroadcastChannel, navigator.serviceWorker) supports more types of data, including binary like Blob, Uint8Array, ArrayBuffer, Map, Set, etc.

Juraj M.

unread,
Jan 2, 2023, 3:59:51 AM1/2/23
to Chromium Extensions, wOxxOm
Oh, you are right. That's bad. Thanks!

So I can't use any API that expects tabId / windowId since it doesn't have one.
And I can't for sure make a screenshot of it.
So now I should create a new bug, requesting screenshot capability (some new API?) for the offscreen document, right?

Also, do you know what does the "IFRAME_SCRIPTING" mean?

wOxxOm

unread,
Jan 2, 2023, 4:45:22 AM1/2/23
to Chromium Extensions, juraj....@gmail.com, wOxxOm
It's already reported in https://crbug.com/1214847

IFRAME_SCRIPTING, based on a popular use case, must be about loading a web site in an iframe to scrape its data via a content script.

Juraj M.

unread,
Jan 2, 2023, 4:55:23 AM1/2/23
to Chromium Extensions, wOxxOm, Juraj M.
I meant "chrome.tabs.captureVisibleTab", the " tabCapture" for capturing streams or something like that, I haven't use that yet.
So I guess I want to use "IFRAME_SCRIPTING", plus the screenshot, thanks!

Juraj M.

unread,
Jan 2, 2023, 5:24:03 AM1/2/23
to Chromium Extensions, Juraj M., wOxxOm
New bug created:

Implement "chrome.tabs.captureVisibleTab" for the upcoming Offscreen Document API

Simeon Vincent

unread,
Jan 6, 2023, 12:31:33 AM1/6/23
to Juraj M., Chromium Extensions, wOxxOm
But there is only "runtime" namespace available???

Apologies for the confusion caused by the lack of docs here. We were hoping to have usage materials ready for the community before EOY vacations, but it slipped to early 2023 for unexciting reasons (time constraints, resourcing, prioritization, yadda yadda). We're actively working on docs and samples together as soon as possible.

To address your question more directly, the main goal of the Offscreen API is to give devs writing MV3 extensions ways to use web platform features that require DOM a way to use these features from the extension service worker. For example, interacting with the clipboard (PR for a work-in-progress example), playing audio, recording a tab, etc. Tab capture is actually one of the use cases that I'd like to tackle as part of this work.

IFRAME_SCRIPTING, based on a popular use case, must be about loading a web site in an iframe to scrape its data via a content script.

When I hear "scraping" I think of fetching static content (specifically HTML) from a given URL and extracting pieces of data from the response. Static data extraction is definitely covered by IFRAME_SCRIPTING, but so is inserting data into a page and automating background interactions with websites. Given that, we felt "scraping" was a bit too narrow of a name for what we were trying to cover. 

Our docs don't currently have descriptions for individual reason values, so I recently opened #4788  to track this work. 👍 reactions on issues are welcome :)

Simeon - @dotproto
Chrome Extensions DevRel


--
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/bd61cc73-bd7d-45a6-a0c8-283461c9d7d8n%40chromium.org.
Reply all
Reply to author
Forward
0 new messages