MV3 alternative for: `new DOMParser().parseFromString`

1,098 views
Skip to first unread message

Juraj M.

unread,
Jun 9, 2022, 3:49:56 AM6/9/22
to Chromium Extensions
Is there some planned workaround that will land this year?

All I need is get `document.title` and some favicons links from the `head`. I guess I could parse it manually with some regexp but I'm not happy about that.

And I for sure don't want to open a new tab/window for that.
And bundling 3MB library mentioned in docs in the service worker sounds insane, especially if I can't load it dynamically on demand.

Robbi

unread,
Jun 11, 2022, 8:24:43 AM6/11/22
to Chromium Extensions, juraj....@gmail.com
"Insane" is the right term.
So I wonder why that 3MB library is not acquired by big G and wired into its browser.

wOxxOm

unread,
Jun 11, 2022, 10:12:20 AM6/11/22
to Chromium Extensions, Robbi, juraj....@gmail.com
It might be implemented in the future as an API https://crbug.com/1056354 or as an Offscreen document.
Meanwhile you can keep using MV2 or find a regex-based HTML parser that arguably works for 99.999% of cases.
Note that it's possible to load the library dynamically on demand in SW context, see "importScripts inside a listener" in https://stackoverflow.com/q/66408379.

Juraj M.

unread,
Jun 11, 2022, 11:27:13 AM6/11/22
to Chromium Extensions, wOxxOm, Robbi, Juraj M.
Thanks for those links! @wOxxOm Too bad it's still not implemented.
I've already spend half a day implementing generic workaround that will inject content script into opened tab which will mine the data using querySelectorAll + getAttribute.
Maybe I should have waited a bit longer....

I've already seen your amazing response about dynamic imports in the StackOverflow but it's not compatible with my current Webpack build system. So as I'm refactoring my extensions to MV3, I'm simply removing all dynamic imports from the background script :(.

Simeon Vincent

unread,
Jun 27, 2022, 10:47:16 PM6/27/22
to Juraj M., Chromium Extensions, wOxxOm, Robbi
As wOxxOm suggested, we plan to support document parsing through the introduction of Offscreen Documents. Implementation of this capability is being tracked in issue 1339382.

We're interested in adding support for dynamic import in extension service workers but don't have any specific plans or work schedule for this yet.

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/fd33e9b3-0798-4c36-a5b8-8de99bbdd231n%40chromium.org.
Reply all
Reply to author
Forward
0 new messages