首页 > 解决方案 > chrome 扩展对 .js 没有任何作用

问题描述

我是 chrome 扩展的新手,但正在尝试设置 XSS 检测器。我有能力分别测试 GET 和 POST,所以我现在只对 GET 进行了编程。扩展加载,但是当我从已知站点进行测试时,扩展什么也不做。还设置了一个什么都没有得到的控制台日志,所以我知道扩展程序没有正确连接。任何关于为什么这不起作用的帮助将不胜感激。

我在 manifest.json 中尝试了 content_scripts,但随后在 xss_detector.js 中得到“Uncaught TypeError: Cannot read property 'onBeforeRequest' of undefined”

清单.json

{
    "name": "XSS Detector", 
    "version": "1.0",
    "manifest_version": 2,
    "description": "xss detector and frame buster", 
    "permissions": ["tabs", "notifications", "<all_urls>", "webRequest"
    "webRequestBlocking"],
    "background": {
     "scripts": ["xss_detector.js"], 
     "persistent": true
},
    "browser_action": {
     "default_title": "Detects and Busts!",
     "default_icon": "icon.png" 
}
}

xss_detector.js

chrome.webRequest.onBeforeRequest.addListener(function(details) {

    const start_script_re = /.*(<div>\s*)?<script>.*<\/script>
    (<\/div>\s*?.*/mi;

    const end_script_re = null;

    if (details.method === "GET") {
    console.log("http get request");
        if (decodeURI(details.url).match(start_script_re)) {
        return {redirectURL:"javascript:"};
    }

    } else if (details.method === "POST") {

    }
}, {
    urls: ["<all_urls>"]
}, ["blocking", "requestBody"]);

清单.json

{
  "name": "XSS Detector",   
  "version": "1.0",
  "manifest_version": 2,
  "description": "xss detector and frame buster", 
  "permissions": ["tabs", "notifications", "<all_urls>", "webRequest", "webRequestBlocking"],
  "background": {
     "scripts": ["xss_detector.js"], 
     "persistent": true
},
  "browser_action": {
     "default_title": "Detects and Busts!",
     "default_icon": "icon.png" 
}
}

标签: google-chrome-extension

解决方案


推荐阅读