繁体   English   中英

chrome扩展执行脚本不适用于content_script

[英]chrome extension execute script not working with content_script

目的是在单击按钮时将内容脚本注入到Google chrome扩展程序的事件页面脚本中,而没有弹出菜单。 当前错误消息是

tabs.executeScript: Cannot access a chrome:// URL

在content_script中会提出一个提取请求,如果您对此有任何提示,也将不胜感激。

事件页面内容脚本

chrome.browserAction.onClicked.addListener(function (tab) {
  chrome.tabs.executeScript(null, {file: "content_script.js"});
});

表现

{
  "manifest_version": 2,

  "name": "Seneca One add Bookmark",
  "description": "Posts URL to database.",
  "version": "2.0",
  "background": {
    "scripts": ["eventPage.js"],
    "persistent": false
  },
  "browser_action": {
    "default_icon": "Favicon@2x.png",
    "default_title": "Add bookmark"
  },
  "content_scripts": [
  {
    "matches": ["http://*/*"],
    "js": ["content_script.js"]
  }
],
  "permissions": [
    "activeTab",
    "storage",
    "tabs",
    "http://*/*",
    "https://*/*"
  ]
}

当他说您要在chrome扩展程序上打开脚本时,@ woxxom是正确的。 使用浏览器操作创建popup.html,然后使其运行并立即关闭。 确保您的popup.js位于清单中的default_script:popup.js中。 然后,您可以在清单中设置背景{persistent:true},以使脚本在每个页面上运行背景并侦听您的提取。 因此,与您所寻找的基本上相同的效果。 单击您的图标,您的popup.html / popup.js运行抓取操作/立即消失,而背景js在后台应答中运行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM