【问题标题】:background.js is being triggered every refresh每次刷新都会触发 background.js
【发布时间】:2016-06-29 14:17:48
【问题描述】:

似乎每次刷新都会触发我的 background.js [植入警报,每次刷新我都会看到它,而且我的上下文菜单正在复制其内部自我]。

这是我的清单文件:

"manifest_version": 2,
"name": "test",
"description": "test",
"version": "1.0",
"permissions": [
    "activeTab",
    "storage",
    "tabs",
    "contextMenus", 
    "https://*/*",
    "http://*/*",
    "https://www.google.com/_/chrome/newtab*"
],
"browser_action": {
    "default_icon": "raj_robot.png",
    "default_title" : "MemoMi"
},
"chrome_url_overrides" : {
    "newtab" : "mypage.html"
},
"background": {
    "scripts" : ["background.js"]
},
"content_scripts": [
{
    "matches": ["<all_urls>"],
    "js" : ["selection.js"],
    "run_at": "document_end"
}
],

这是我的后台脚本:

function handle_click() {
    alert("hi there!");
}

chrome.contextMenus.create({

    title: "menu title", 
    contexts:["selection"], 
    onclick: handle_click

});

我在这里做错了什么?

谢谢! 古拉

【问题讨论】:

  • 您的后台脚本中有什么?此外,您的内容脚本,因为(IIRC)这是唯一应该刷新的脚本。
  • 已添加到问题中。谢谢

标签: google-chrome plugins google-chrome-extension google-chrome-devtools google-chrome-app


【解决方案1】:

好的,我找到了。我实际上是通过使用内容脚本中的方法来隐式触发 background.js,这应该在 background.js 中。只需将您的代码注释掉,看看它是否有所改进。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-29
    • 2018-05-07
    • 2017-02-13
    • 1970-01-01
    • 2011-07-06
    • 1970-01-01
    • 2020-01-12
    • 2015-08-03
    相关资源
    最近更新 更多