首页 > 其他 > 详细

只有一个按钮的插件

时间:2020-06-03 21:24:38      阅读:42      评论:0      收藏:0      [点我收藏+]

1 manifest.json

{
  "name": "Hello Extensions",
  "description": "Base Level Extension",
  "version": "1.0",
  "manifest_version": 2,
  "browser_action": {
    // "default_popup": "hello.html",   
    "default_icon": "hello_extensions.png"
  },
  "commands": {
    "_execute_browser_action": {
      "suggested_key": {
        "default": "Ctrl+Shift+F",
        "mac": "MacCtrl+Shift+F"
      },
      "description": "Opens hello.html"
    }
  },
  "permissions": [
    "tabs",
    "unlimitedStorage",
    "notifications",
    "history",
    "activeTab",
    "storage",
    "webRequest",
    "webRequestBlocking",
    "http://*/*",
    "https://*/*"
  ],
  "background": {
    "scripts": ["background.js"],
    "persistent": true
  }
}

2 background.js

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

3 wolbo.js

console.log("hehe");
alert("hehe");

成功注入了

注意事项:

 1 要么选中popup 要么选择运行脚本 只能二选一

 2 Cannot access contents of url “data:text/html,chromewebdata” 是缺少权限增加权限就行了

 3 webrequest权限需要开启常驻  "persistent": true

 

 

 

 

 

参考:

https://stackoverflow.com/questions/7168362/run-script-each-time-chrome-extension-icon-clicked

https://stackoverflow.com/questions/13326105/using-webrequest-api-with-event-page  

https://stackoverflow.com/questions/37093152/unchecked-runtime-lasterror-while-running-tabs-executescript-cannot-access-cont

https://www.cnblogs.com/giggle/p/8082672.html

 

只有一个按钮的插件

原文:https://www.cnblogs.com/wolbo/p/13040043.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!