'Extension's context menu on Safari does not show quote and emoji
Solution 1:[1]
It's working now
For some reasons, the extension builder of Xcode bundled the javascript strings wrongly
A solution is to convert the background.js to UTF-16. It involve three steps:
- Open the background.js in VS Code, and then click the UTF-8 button in the status bar:
- Select Save with encoding
- Select UTF-16 LE
Final step, build the Xcode Safari Extension project. You can now use accented characters and emojis to your heart's content
If anyone have a good idea why Xcode cannot build Safari extension straight out of a UTF-8 file, please offer some theory why it is so. Or if there are any other alternative solution to this problem
A bit shorter steps (two steps), use iconv commandline utility to convert the UTF-8 file background.js to UTF-16LE, but it's not enough, the emojis and other characters still looks gibberish when Xcode build the project. Still need another step, that is, open the background.js in VS Code and then save it (Ctrl+S or command+S). Looks like VS Code is doing some corrections to a file when a file is set to different encoding. Final step, build the Xcode Safari Extension project
Solution 2:[2]
Setting the background.js to UTF-8 with BOM also works
Here's an example script of converting a file to UTF-8 with BOM:
(rm -f background.js && cd background-src && parcel build background.mjs && mv ./dist/background.js ../x.js && rm -rf ./dist/ && rm -rf ./.parcel-cache/ && rm -rf ./.cache/ && echo -ne '\xEF\xBB\xBF' > ../background.js && cat ../x.js >> ../background.js && rm ../x.js)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Michael Buen |







