Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Re: [crx] ExecutionWorld of userScript

103 views
Skip to first unread message

Oliver Dunk

unread,
May 8, 2025, 6:11:01 AMMay 8
to Liang Cui, Chromium Extensions
Hi Liang,

I would encourage having user scripts use the USER_SCRIPT world, as this isolates them from the page, but still prevents them from having unnecessary access to extension APIs.

As a note, unless you choose otherwise all user scripts will use the same user script world. As a result, you should be able to inject jQuery once and avoid needing to include it for every user script.
Oliver Dunk | DevRel, Chrome Extensions | https://developer.chrome.com/ | London, GB


On Tue, Apr 8, 2025 at 9:17 AM Liang Cui <cuili...@gmail.com> wrote:
I am trying to migrate my browser extension from MV2 to MV3. The purpose of this extension is to communicate with a Native Host to implement some automation controls.

In my content script, I have included jQuery and some helper functions. When I use userScript.execute() to run some dynamic code which use jQuery or the helper functions, I encounter an error saying "These methods cannot be found." After checking the documentation, I found that the ExecutionWorld for userScript can only be set to MAIN or USER_SCRIPT, and it does not support using the ISOLATED world as in content scripts.

I am facing the following choices:

Use USER_SCRIPT, and for each UserScript, insert the jQuery code and helper methods before the main code.

Use MAIN for both ContentScript and UserScript, which might cause conflicts.

Is there a better option? Would it be possible to allow userScript.execute() to run in the ISOLATED world?

Thank you!

--
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 visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/941d972f-bbd4-4632-85aa-06f0742e7aacn%40chromium.org.
Reply all
Reply to author
Forward
0 new messages