Kocal / vue-web-extension

🛠️ A Vue CLI 3+ preset (previously a Vue CLI 2 boilerplate) for quickly starting a web extension with Vue, Babel, ESLint and more!
https://vue-web-extension.netlify.app/
MIT License
1.58k stars 167 forks source link

Unable to send message from backgrund.js to content_script.js. #590

Closed kurohoan closed 4 years ago

kurohoan commented 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');
kurohoan commented 4 years ago

Please help me.

kurohoan commented 4 years ago

It was solved by adding the following description.

Thank you very much.

"persistent": false &

    "matches": [
      "http://*/*",
      "https://*/*"
    ],