Google registerContentScripts sample doesn't work with Safari 16.4.*

The Safari 16.4.* release docs appear to suggest that Safari now supports registerContentScripts. However, though it no longer throws a method not found error, the actual function doesn't appear to do anything in any of my tests, in either 16.4.0 or now 16.4.1.

https://github.com/GoogleChrome/chrome-extensions-samples/scripting

Has an example that shows an alert when a script is registered using registerContentScripts. If you run

xcrun safari-web-extension-converter scripting/

On the directory it successfully creates a Safari extension project that works for everything except the registerContentScripts call (after adding icons!). It just silently does nothing, with no log or error, whereas everything else works the same as in Chrome.

Is anything available on the web anywhere that someone has seen actually working in a real browser? If not I will try and submit a bug report but if I'm just holding it wrong...

Accepted Answer

Hi! I see that the extension requests access to https://example.com/ but have you explicitly granted the extension access to the site? The script won't inject unless access has been granted. If you've done this and you're still experiencing this issue, please file a bug with Feedback Assistant at https://developer.apple.com/bug-reporting/.

Ok, not sure what was happening there - I must have been holding it wrong... Turns out that example does work when you add host_permissions, at least when they are specified correctly! :-).

My bad... sorry for the noise!

Google registerContentScripts sample doesn't work with Safari 16.4.*
 
 
Q