I cannot send message from my background script to content script except i remove the popup.html from the browser action in the manifest.json. Someone help me
background.js
// Called when the user clicks on the browser action.
chrome.browserAction.onClicked.addListener(function(tabs) {
// Send a message to the active tab
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
var activeTab = tabs[0];
chrome.tabs.sendMessage(tabs[0].id, {"message": "clicked_browser_action"});
});
});
// This block is new! and will be used later
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if( request.message === "open_new_tab" ) {
chrome.tabs.create({"url": request.url});
}
}
);
content.js
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if( request.message == "clicked_browser_action" ) {
console.log("Congratulations you can now work!");
// This line is new!
chrome.runtime.sendMessage({"message": "open_new_tab", "url": firstHref});
}
}
);
manifest.json
{
"name": "Wowprezi lead tool",
"version": "1.0",
"description": "Extension to find leads and add to sales force!",
"author": "Djouonang Landry",
"manifest_version": 2,
"content_security_policy": "script-src 'self' https://ssl.google-analytics.com; object-src 'self'",
"background": {
"persistent": true,
"scripts": ["js/background.js"]
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["js/jquery-3.3.1.min.js","js/content.js"],
"all_frames": true
}
],
"browser_action": {
"default_popup": "html/popup.html",
"default_title": "Find leads"
}
}
popup.html - Except this is removed from the manifest.json i cannot send message from background to content.js. Please note i use the console function to check if the message was sent across to the content.js