Hi, I am developing the Click & Read web add-on for Chromium, Firefox and Safari.
We use xcrun safari-web-extension-converter
tool to generate the Safari add-on. The build on Xcode had no meaning errors/warnings, until we had to switch to a more up-to-date MacBook (required as deprecated Mac had no support for latest macOS and thus for Xcode compatibility !).
So now I build my add-on on an Apple M1 MB Air on Sequoia 15.0 with latest Xcode, but I encounter an error ? or warning ? :
NSBundle file:///System/Library/PrivateFrameworks/MetalTools.framework/ principal class is nil because all fallbacks have failed
Unable to create bundle at URL ((null)): normalized URL null
Unable to create bundle at URL ((null)): normalized URL null
Unable to create bundle at URL ((null)): normalized URL null
But it doesn't prevent the add-on build to complete as I am able to open it onto Safari. Then, when loading the add-on on a test web page, I get this error on safari console:
Error: Invalid call to runtime.connect(). No runtime.onConnect listeners found.
BTW, the same add-on Dist works as expected on Chrome or Firefox (on macOS).
So it seems the runtime listener runtime.onConnect.addListener
isn't initiated on Background script...
Thanks for your feedback and help
The source code does differ from the App Store version, and the attached code fails to parse background.js
due to the added diacritics mapping and how the file is being minified. The \u...
escape sequences are being converted into literal UTF-8 characters when minified, but the script itself is not being loaded with the correct UTF-8 encoding, leading to a parse error. (You can see this error in the Develop > Web Extension Background Content menu for your extension.)
This issue is not specific to Safari 18. We have observed the same parse error with Safari 17, so it’s not a regression in Safari 18. Chrome and Firefox appear to have different auto-detection rules for text encodings compared to Safari.
Here are a few workarounds you can try:
- Add
"type": "module"
to thebackground
field in your manifest. This will force the scripts to load as UTF-8, as modules require UTF-8 encoding. - Use a
page
background and provide your own HTML file. Include the script using<script src="background.js" charset="utf8"></script>
, ensuring it’s loaded with the correct encoding. - Add a UTF-8 BOM to the beginning of the
background.js
file to force UTF-8 encoding.