简体   繁体   English

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

[英]chrome extension execute script not working with content_script

Aim is to inject a content script into a eventpage script in google chrome extension with no popup menu when button is clicked. 目的是在单击按钮时将内容脚本注入到Google chrome扩展程序的事件页面脚本中,而没有弹出菜单。 Current error message is 当前错误消息是

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

In the content_script a fetch request is made, if you have any tips on that as well it would be greatly appreciated. 在content_script中会提出一个提取请求,如果您对此有任何提示,也将不胜感激。

Event Page Content Script 事件页面内容脚本

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

Manifest 表现

{
  "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://*/*"
  ]
}

@woxxom is correct when he says you are opening a script on a chrome extension. 当他说您要在chrome扩展程序上打开脚本时,@ woxxom是正确的。 Make a popup.html with the browser action and then just make it run and then close itself instantly. 使用浏览器操作创建popup.html,然后使其运行并立即关闭。 Make sure your popup.js is in the default_script : popup.js in your manifest. 确保您的popup.js位于清单中的default_script:popup.js中。 Then you could make background { persistent : true } in your manifest to make your script working the background on every page and listening for your fetch. 然后,您可以在清单中设置背景{persistent:true},以使脚本在每个页面上运行背景并侦听您的提取。 So essentially the same effect of what you are looking for. 因此,与您所寻找的基本上相同的效果。 You click the icon your popup.html/popup.js runs the fetch / instantly disappears, while your background js is running in the background answering. 单击您的图标,您的popup.html / popup.js运行抓取操作/立即消失,而背景js在后台应答中运行。

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

相关问题 Chrome扩展程序content_script隔离 - Chrome extension content_script isolation 尝试在chrome扩展(JavaScript)中从default_script到content_script进行通信无法正常工作 - Trying to communicate from default_script to content_script in chrome extension (JavaScript) not working jQuery未加载到Google Chrome content_script扩展名中 - jQuery not loading in Google Chrome content_script extension 在background和content_script之间打开一个用于chrome扩展的消息端口 - Opening a message port between background and content_script for a chrome extension AJAX被阻止来自chrome扩展content_script - AJAX Blocked from chrome extension content_script chrome扩展通信网页-> content_script-> popup.js - chrome extension communication web page -> content_script -> popup.js Chrome扩展程序:从content_script访问页面的HTML5 localStorage - Chrome Extension: access page's HTML5 localStorage from content_script 无法将鼠标坐标从 content_script 传递到弹出窗口(chrome 扩展) - can't pass mouse coordinates from content_script to popup (chrome extension) 如何在不单击 chrome 插件中的插件图标的情况下执行 content_script? - how to execute content_script without clicking on the plugin icon in chrome plugin? document_start 和 document_end 处的 Chrome 扩展 content_script - Chrome Extension content_script at both document_start and document_end
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM