Chrome extension injecting script get error

后端 未结 1 1306
庸人自扰
庸人自扰 2020-12-21 14:44

On injecting the script by using command

chrome.tabs.executeScript(
  null, {file: \"dialog.js\"});

throwing error

Unchecked runti

相关标签:
1条回答
  • 2020-12-21 15:19

    Please explicitly set the tabId parameter of executeScript, which by default would be the active tab of the current window.

    If you couldn't get tabId directly, use chrome.tabs.query to query tab state.

    chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
        for(var i = 0; i<tabs.length;i++) {
            chrome.tabs.executeScript(tabs[i].id, {"file": "dialog.js"});
        }
    });
    

    And don't forget add "web_accessible_resources": ["dialog.js"] in your manifest.json

    0 讨论(0)
提交回复
热议问题