I have a content script that is declared as
"content_scripts": [
{
“matches”: ["<all_urls>"],
“js”: [“js/content.js”]
}
],
My background scripts are declared as
{
“background”: {
“scripts”: [ “js/storage.js”, “js/background.js”]
},
My permissions are
"permissions": [ “storage”, “contextMenus”, “http:///”, “https:///”,
“activeTab”, “tabs”,“clipboardRead”, “clipboardWrite” ],
To send a message from background.js I use
function sendCopyToContentScript( toBeCopied){
chrome.tabs.query({active: true, currentWindow: true},
function(tabs) {
console.log("sending " + toBeCopied);
chrome.tabs.sendMessage( tabs[0].id, {data: toBeCopied, dir:‘inClpbrd’},
function(){} );
});
}
In content.js, I use this to react to the message sent
chrome.runtime.onMessage.addListener(
function (request, sender){
if (request.cmd) {
…
}
else if (request.data) {
console.log("received from background " + request.data + " " +
request.dir);
if (request.dir == “fromClpbrd”) {
insertTextAtCursor(request.data);
}
else if (request.dir == “inClpbrd”){
if(document.getElementById(‘filteredClipboard_data’) == null){
var ta = document.createElement(‘textarea’);
ta.contentEditable = “true”;
ta.id = ‘filteredClipboard_data’;
document.body.appendChild(ta);
}
ta.value = request.data;
ta.select();
document.execCommand(“Copy”);
}
}
});
However I don’t see the “received from background” message and I get the
error
Unchecked lastError value: Error: Could not establish connection. Receiving
end does not exist.
Thanks for any help
François