为什么在安装Chrome应用后,它会在新标签上触发?

问题描述 投票:-1回答:1

我创建了一个Chrome应用,你可以在这里试试

https://chrome.google.com/webstore/detail/style-scout/chbdclbnkfcocaolknbjmmppendkmebh

但是在我安装它并打开一个新的水龙头后,应用程序会立即启动并且只是第一次...为什么会发生这种情况?

清单是

{
    "background":
    {
        "scripts": ["background.js"]
    },
    "browser_action":
    {
        "default_icon": "icon-128.png",
        "default_title": "Style Scout"
    },
    "content_security_policy": "script-src 'self' https://ssl.google-analytics.com; object-src 'self'",
    "name": "Style Scout",
    "short_name": "Style Scout – Fonts & Colors Finder",
    "description": "Fonts & Colors Finder",
    "homepage_url": "https://stylescout.org",
    "icons":
    {
        "16": "icon-16.png",
        "48": "icon-48.png",
        "128": "icon-128.png"
    },
    "permissions": ["tabs", "http://*/*", "https://*/*", "storage"],
    "version": "0.612",
    "manifest_version": 2,
    "content_scripts": [
    {
        "matches": ["<all_urls>"],
        "js": ["activate-np-chrome.js"]
    }],
    "web_accessible_resources": ["np-chrome.js"]
}

和background.js:

chrome.browserAction.onClicked.addListener(function(tab) {
    chrome.tabs.executeScript(tab.id, {
        file: "np-chrome.js"
    })
});

np-chrome.js是我的应用程序的实际完整脚本...

javascript google-chrome google-chrome-extension
1个回答
0
投票

好的,我完全删除了这部分

  "content_scripts": [
{
    "matches": ["<all_urls>"],
    "js": ["activate-np-chrome.js"]
}],
"web_accessible_resources": ["np-chrome.js"]

现在它可以正常工作,因为我不知道content_scripts实际上是为每个单独的选项卡注入和触发脚本,而我只需要在用户单击我的浏览器按钮时触发我的脚本

© www.soinside.com 2019 - 2024. All rights reserved.