I am experiencing the same behaviour.
Listener in background script:
browser.runtime.onMessageExternal.addListener((request, sender, sendResponse) => {
console.log("Received request: ", request);
sendResponse({farewell: "Goodbye from the background page!"});
});
console.log("background script onMessageExternal subscribed by", browser.runtime.id);
and web page is this:
<html>
<head>
</head>
<body>
<h1>testing sendMessage</h1>
<script>
console.log("abc....");
browser.runtime.sendMessage("com.example.Sample-App.Extension (DY.....84)", { greeting: "Hello!" }, function (response) {
console.log("Received response from the background page:", response);
});
</script>
</body>
</html>
I'm hosting it via https, like https://83cc-82-172-140-54.ngrok-free.app and manifest is this:
{
"manifest_version": 3,
"default_locale": "en",
"name": "__MSG_extension_name__",
"description": "__MSG_extension_description__",
"version": "1.0.5",
"icons": {
"16": "images/icon-16.png",
"32": "images/icon-32.png",
"48": "images/icon-48.png",
"96": "images/icon-96.png",
"128": "images/icon-128.png",
"256": "images/icon-256.png",
"512": "images/icon-512.png"
},
"background": {
"service_worker": "scripts/background.js"
},
"content_scripts": [
{
"js": [
"scripts/content.js"
],
"css": [
"styles.css"
],
"matches": [
"https://example.com/messages/*"
],
"all_frames": true
}
],
"options_ui": {
"page": "options/browser/options.html",
"open_in_tab": true
},
"action": {
"default_popup": "popup/browser/popup.html",
"default_icon": {
"16": "images/toolbar-icon-16.png",
"19": "images/toolbar-icon-19.png",
"32": "images/toolbar-icon-32.png",
"38": "images/toolbar-icon-38.png",
"48": "images/toolbar-icon-48.png",
"72": "images/toolbar-icon-72.png"
}
},
"permissions": [
"storage"
],
"externally_connectable": {
"matches": [
"https://83cc-82-172-140-54.ngrok-free.app/*"
]
}
}
And still opening the page, I see in console logs only:
[Log] abc.... (83cc-82-172-140-54.ngrok-free.app, line 10)
[Log] Received response from the background page: – undefined (83cc-82-172-140-54.ngrok-free.app, line 12)
What I am missing?
Running on Safari Version 17.0 (19616.1.27.211.1).
If I replace browser
with chrome
-- it is working on Chrome BTW.