I use the scripting API quite
extensively in my new v3 extension (migrating from a v2) and there
seems to be some odd things.
I have a script border.js which gets
injected into a tab by the service worker:
chrome.scripting.executeScript( {
target: {tabId: tabId},
files: ["border.js"],
world:
chrome.scripting.ExecutionWorld.MAIN,
}, function (e) {
console.log("Added
border.js");
});
And at one point border.js calls:
chrome.runtime.sendMessage(extensionid,
{action: 'openlink', payload: $(this).prop('href')},
function(response) {
console.log('Openlink message sent');
});
To send a message back to the service
worker...
The console complains that I need to
send the id of the extension. But when I call
chrome.runtime.id it
is undefined so I need to hard code the extension id.
When I do that (hard-code) the message
never arrives at the service worker (background.js) even though I
see the "openlink message sent" in the console for the page.
I assume I'm missing something that has
changed between v2 and v3 any suggestions?
Thanks,
Mark