I really don't know why this isn't working, I have a background.js:
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
setTimeout(() => {
chrome.tabs.sendMessage(tabs[0].id, {name: "test"}, (response) => console.log(response))
}, 1000)
})
content.js:
chrome.runtime.onMessage.addListener((message) => {
console.log("message:", message.name)
})
manifest.json:
{
"name": "Test",
"version": "0.1.7",
"description": "blah blah",
"manifest_version": 3,
"background": {
"service_worker": "background.js"
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content.js"]
}
],
"permissions": [
"activeTab",
"desktopCapture"
],
"action": {
"default_title": "Click!"
}
}
When I click the extension, I get this in the dev tool console:
Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.
And this in the browser console:
extensions.js:2897 Uncaught TypeError: Failed to construct 'URL': Invalid URL
at ExtensionsErrorPageElement.onSelectedErrorChanged_ (extensions.js:2897:2882)
at Object.re [as fn] (polymer_bundled.min.js:1:24397)
at se (polymer_bundled.min.js:1:24155)
at ee (polymer_bundled.min.js:1:23929)
at ExtensionsErrorPageElement._propertiesChanged (polymer_bundled.min.js:1:33807)
at ExtensionsErrorPageElement._flushProperties (polymer_bundled.min.js:1:17256)
at ExtensionsErrorPageElement._flushProperties (polymer_bundled.min.js:1:32692)
at ExtensionsErrorPageElement._invalidateProperties (polymer_bundled.min.js:1:32509)
at ExtensionsErrorPageElement._setProperty (polymer_bundled.min.js:1:32438)
at Object.defineProperty.set (polymer_bundled.min.js:1:15801)
What am I doing wrong?? Thanks in advance!
I also tried the background.js without setTimeout
, but got the same error. I thought it was called too early, before the content script is loaded, so I delayed it a bit, but same result.