変更前
manifest.json
{
...
"manifest_version": 3,
"permissions": [
"tabs",
"scripting"
],
...
}
content.js
chrome.runtime.sendMessage({}, () => {});
background.js
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
getNextTabAction();
return true;
});
async function getNextTabAction() {
const next_tab = ...;
chrome.scripting.executeScript({
target: {tabId: next_tab},
function: () => {
console.log("-_-");
}
});
return true;
}
エラーコード
caught (in promise) Error: Cannot access contents of url "「タブのURL~」".
Extension manifest must request permission to access this host.
変更後
manifest.json
{
...
"manifest_version": 3,
"permissions": [
"tabs",
"scripting"
],
// 以下を追加するだけ
"host_permissions": ["http://*/*", "https://*/*"],
...
}
これで目標のタブ(今回はnext_tab)のコンソールに「-_-」が追加されると思います。