首页 > 解决方案 > Chrome 扩展程序无响应(browser_action 和后台脚本)

问题描述

知道为什么单击复选框时以下 chrome 扩展响应非常慢吗?

我尝试使用 page_action,但这阻止了该chrome.browserAction.setBadgeBackgroundColor功能。

我想从 background.js 脚本更改扩展程序的图标,但是 options.html 不能正常工作。

清单.json:

{
    "name": "name",
    "description": "desc",
    "manifest_version" : 2,
    "version" : "0.1.0",
    "icons": {
    },
    "web_accessible_resources": [
    ],
    "options_page": "options.html",
    "background": {
      "scripts": ["background.js"],
      "persistent": false
    },
    "browser_action": {
        "default_title": "def title",
        "default_popup": "options.html"
    },
    "permissions": [
        "background",
        "notifications",
        "http://*/",
        "https://*/"
    ]
}

选项.html:

<!DOCTYPE HTML>
<html>
<head>
    <title>Title</title>
</head>
<body>
<div>
    <div class="p-2">
        <form>
            <div>
                <input type="text" name="input_text" id="input_text" />
                <label for="input_text">Text input</label>
            </div>
            <div>
                <input type="checkbox" name="cb1" id="cb1" />
                <label for="cb1">Checkbox 1</label>
            </div>
            <div>
                <input type="checkbox" name="cb2" id="cb2" />
                <label for="cb2">Checkbox 2</label>
            </div>
            <div>
                <input type="submit" name="submit" value="Submit"/>
            </div>
        </form>
    </div>

</div>
</body>
</html>

背景.js:

function changeIconBackground() {
  chrome.browserAction.setBadgeBackgroundColor({color: [255, 255, 0, 200]});
}
changeIconBackground();

标签: google-chrome-extension

解决方案


推荐阅读