Accessing window object in manifest V3

493 views
Skip to first unread message

Sagar Mittal

unread,
Aug 8, 2023, 7:13:09 AM8/8/23
to Chromium Extensions
Hi all,

I have an extension in manifest V2 and want to migrate it to V3. On doing that I am getting the following error (see Error(2).png attachment):

I see that I need to replace the window object with Offscreen APIs. However, I am not able to figure out how to do it. Could someone please help me with this? Is there any example that i can refer to?

Thanks
Error (2).png

Oliver Dunk

unread,
Aug 8, 2023, 7:31:15 AM8/8/23
to Sagar Mittal, Chromium Extensions
Hi Sagar,

It looks like you might be using some sort of library - could you share some more about what you're trying to do?

Offscreen documents are one way to use DOM APIs in an MV3 extension, but there may be a better solution for your particular use case.
Oliver Dunk | DevRel, Chrome Extensions | https://developer.chrome.com/ | London, GB


--
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/e60477bd-8581-4115-b133-00eb43b9707cn%40chromium.org.

wOxxOm

unread,
Aug 8, 2023, 7:48:09 AM8/8/23
to Chromium Extensions, Oliver Dunk, Chromium Extensions, Sagar Mittal
If __vssPageContext is defined by a web page then you need a content script in MAIN world to read it (more info) and not a service worker, so maybe you specified your content script as service_worker (or imported it inside) by mistake.

Sagar Mittal

unread,
Aug 9, 2023, 3:26:01 PM8/9/23
to Chromium Extensions, wOxxOm, Oliver Dunk, Chromium Extensions, Sagar Mittal
I added this line at the top of the file and the console error has gone:
const window = self;

Will this solve the problem, or will it break something else?

wOxxOm

unread,
Aug 9, 2023, 4:02:42 PM8/9/23
to Chromium Extensions, Sagar Mittal, wOxxOm, Oliver Dunk, Chromium Extensions
It depends on which `window` features this script is using. Some scripts [incorrectly] use it just as an alias of `globalThis` without relying on any `window` specific features, so redirecting to `self` will work in this case.
Reply all
Reply to author
Forward
0 new messages