Hi, im trying to send message from web page to my extension but i couldn’t get it to work. I tried as in the sample extension in the link below but it didnt work and the sample itself does not work either. Is there a working sample i can use? Thank you for your help.
Here is my code ;
web-page.js
function messageContentScript() {
window.postMessage({
direction: "from-page-script",
message: "Message from the page"
}, "*");
}
content-script.js
window.addEventListener("message", (event) => {
if (event.source == window &&
event.data &&
event.data.direction == "from-page-script") {
console.log("Content script received message: \"" + event.data.message + "\"");
}
});
manifest.json
{
"manifest_version": 2,
"name": "Page to extension messaging",
"description": "Test",
"version": "1.0",
"applications": {
"gecko": {
"id": "test@sample.extensions.thunderbird.net",
"strict_min_version": "74.0b2"
}
},
"content_scripts": [
{
"matches": ["*://localhost:44383/*"],
"js": ["content-script.js"]
}
]