I need to use embedding webextension as I have a legacy SDK. I followed the tutorial in: Embedded Websections and the extension directory contains:
- myExtension, which contains:
- index.js
- package.json
- webextension, which contains:
- manifest.json
- webext.js
Theindex.js
contains:
const webExtension = require("sdk/webextension");
console.log("inside sdk embedded");
function startup({webExtension}) {
// Start the embedded webextension.
webExtension.startup().then(api => {
const {browser} = api;
browser.runtime.onConnect.addListener((port) => {
port.postMessage({
content: "content from legacy add-on"
});
});
});
}
The package.json
contains:
{
"title": "borderify",
"name": "borderify",
"version": "0.0.1",
"description": "sdk addon",
"main": "index.js",
"author": "author",
"engines": {
"firefox": ">=38.0a1",
"fennec": ">=38.0a1"
},
"license": "MIT",
"keywords": [
"jetpack"
]
}
The webext.js contains:
var port = browser.runtime.connect({name: "connection-to-legacy"});
port.onMessage.addListener(function(message) {
console.log("Message from legacy add-on: " + message.content);
});
The manifest.json
contains:
{
"manifest_version": 2,
"name": "borderify",
"version": "1.0",
"description": "Adds a red border to all webpages matching mozilla.org.",
"icons": {
"48": "icons/border-48.png"
},
"content_scripts": [
{
"matches": ["*://*.mozilla.org/*"],
"js": ["webext.js"]
}
]
}
The webext.js
contains:
var port = browser.runtime.connect({name: "connection-to-legacy"});
port.onMessage.addListener(function(message) {
console.log("Message from legacy add-on: " + message.content);
});
However, when I run the SDK using JPM, I get the console message from index.js
which says: "inside sdk embedded"
but I do not get the message which is inside webext.js
. Why is that? Can you help me know how to send messages from the legacy Addon SDK to the webextension addon?