I have an extension where I call
function doScript(window) {
chrome.scripting.executeScript(
{
target: {tabId: window.tabs[0].id},
files: ['myscript.js'],
});
}
myscript.js simply has
alert("Made it")
but I get no alert in my tab.
If I change the tabId to something random like 123
chrome.scripting.executeScript(
{
target: {tabId: 123},
files: ['myscript.js'],
});
then I get an error "Unchecked runtime.lastError: No tab with id: 123"
So it looks like my tabId is right, but for some reason myscript.js is not triggering an alert.
If I mess up the script name like this
chrome.scripting.executeScript(
{
target: {tabId: window.tabs[0].id}},
files: ['ttttttttttt.js'],
});
I get "runtime.lastError: Could not load file: 'ttttttttttt.js'."
I tried looking through the console logs and the only thing I see is this error upon clicking but it looks like a red herring.
"Unchecked runtime.lastError: Cannot access contents of url "". Extension manifest must request permission to access this host." https://github.com/GoogleChrome/web-vitals-extension/issues/54
Here is my manifest
{
"manifest_version": 3,
"name": "pokemon bokemon",
"description": "",
"version": "0.3.0",
"action": {
"default_popup": "popup.html"
},
"icons": {
"16": "icon16.png",
"32": "icon32.png"
},
"permissions": [
"tabs",
"storage",
"scripting",
"activeTab",
"cookies"
],
"host_permissions": [
"*://*/*",
"<all_urls>"
],
"options_page": "options.html"
}
EDIT: Apparently it's a bug in chrome/manifest v3. Opened a bug here: https://bugs.chromium.org/p/chromium/issues/detail?id=1191971
