Support for `world: "MAIN"` in Safari web extension content scripts

Google has been adding support for running content scripts in world: "MAIN" via either registerContentScripts or since Chrome 111 directly on content_scripts in the manifest.

Safari just added registerContentScripts but doesn't support MAIN. Is there a support roadmap for this sort of thing documented somewhere for Safari? A "wontfix" is far more useful than not knowing whether it will be implemented or not in the foreseeable future...

There may be some other way to achieve this but I am just getting started with Apple-specific development, and am finding navigating the docs very difficult, so apologies if this or some other way to achieve what this enables is documented somewhere!

Accepted Reply

Safari 16.4 does support "MAIN" for registerContentScripts.

  • Of course it does... Turns out I had some strange cruft after trying to get things working. My real problem was coming from Safari not using InjectionResults when returning from browser.scripting.executeScript and just returning the results directly. After fixing that, it turns out the registerContentScripts was working... Sorry for the noise! However, someone should update the MDN because, as you point out, Safari 16.4+ RegisterContentScript does support the world parameter!

Add a Comment

Replies

Safari 16.4 does support "MAIN" for registerContentScripts.

  • Of course it does... Turns out I had some strange cruft after trying to get things working. My real problem was coming from Safari not using InjectionResults when returning from browser.scripting.executeScript and just returning the results directly. After fixing that, it turns out the registerContentScripts was working... Sorry for the noise! However, someone should update the MDN because, as you point out, Safari 16.4+ RegisterContentScript does support the world parameter!

Add a Comment

Um, so https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/scripting/RegisteredContentScript is wrong? From my testing it doesn't appear to be wrong... Maybe there are cases when it does work for Chrome but doesn't work for Safari? Maybe it only works on iOS (I only tested on the desktop so far...)?

  • Actually, I'll be honest, I'm no longer getting a method-not-found exception but my scripts registered this way aren't actually getting executed at all, whether isolated or in MAIN. Are there any sample projects that are known to work available anywhere?

    If I put the script I am trying to execute in the manifest, it executes fine. I have, of course, remembered to put the script in web_accessible_resources but I'm getting neither execution nor errors.

Add a Comment