Safari Web Extensions: UTF-8 characters in code are not recognised

UTF-8 characters in JS code strings such as or are not handled properly and come out wrong when displayed/printed.

Replies

You might need to use a UTF-8 BOM on the script file, <script charset="utf-8" src="...">, or encode the characters.
This is happening if you send utf-8 chars from the background or content scripts to the site. Safari still defaults to (Western ISO Latin 1) charset.

Code Block
/* background.js */
sendResponse({error: 'These utf-8 quotes won’t work: “”’‘ we&rsquo;re forced to use html entities like it&rsquo;s 2005.'});
/* content-script.js */
browser.runtime.sendMessage(e.data).then(function(response){
window.postMessage({action: e.data.action, response: response}, window.location.origin);
});