Closed kurohoan closed 4 years ago
Unable to send message from backgrund.js to content_script.js.
Although the alert of "content_script.js" is displayed, "chrome.runtime.onMessage.addListener()" does not start and I cannot receive the message from "background.js". Is something wrong?
background.js
chrome.tabs.query({ active: true, currentWindow: true }, function (t) { chrome.tabs.sendMessage(t[0].id, {action: 'entry'}); });
content_script.js
chrome.runtime.onMessage.addListener( (mess, sender, sendResponse) => { console.log('Get message!'); }); alert('OK');
Please help me.
It was solved by adding the following description.
Thank you very much.
"persistent": false &
"persistent": false
"matches": [ "http://*/*", "https://*/*" ],
Unable to send message from backgrund.js to content_script.js.
Although the alert of "content_script.js" is displayed, "chrome.runtime.onMessage.addListener()" does not start and I cannot receive the message from "background.js". Is something wrong?
background.js
content_script.js