0

I am trying to use chrome.webRequest to intercept and change all requests my browser makes to "https://*.gimkit.com/assets/map/characters/skins/*/spritesheet.png". My manifest.json file is below, along with my code. webRequest.js is supposed to alert "hello" from the function x whenever the site fires an http request. However, this does not happen. Instead, I get an error saying the following:

webRequest.js:9 (anonymous function) webRequest.js:9:chrome.webRequest.onBeforeRequest.addListener(

I am very confused, and am wondering if somebody could point me in the right direction

manifest.json

{
    "name":"Inject DOM",
    "description":"http://stackoverflow.com/questions/14068879",
    "version":"1",
    "manifest_version":3,
    "content_scripts": [
        {
          "matches": ["https://*.gimkit.com/assets/map/characters/skins/*/spritesheet.png"],
          "js": ["myscript.js"]
        },
        {
            "matches": ["https://*.gimkit.com/*"],
            "js": ["webRequest.js"]
        }
    ],
    "permissions": [
        "webRequest"
    ],
    "host_permissions": [
        "https://*.gimkit.com/assets/map/characters/skins/*/spritesheet.png"
    ]
}

webRequest.js

function x() {
    alert("hello")
}


var filter = {urls: ["<all_urls>"]};
var extraInfoSpec = [{"redirectUrl" : "https://static.wikia.nocookie.net/gimkit/images/a/aa/Gimkitaprilfools2023skin.png/revision/latest/scale-to-width-down/1000?cb=20230401115318"}];

chrome.webRequest.onBeforeRequest.addListener(
  x,             // function
  filter,               //  objects
  extraInfoSpec         //  optional array of strings
)

myscript.js

//Clear Page
body = document.getElementsByTagName("BODY")[0];
//Force sunny skin
body.innerHTML = '<img style="display: block;-webkit-user-select: none;margin: auto;background-color: hsl(0, 0%, 90%);transition: background-color 300ms;" src="https://www.gimkit.com/assets/map/characters/skins/sunny/spritesheet.png">';

The expected outcome is that an alert of "hello" would pop up when the site makes an http request. However, this does not happen, and I get an error.

webRequest.js:9 (anonymous function) webRequest.js:9:chrome.webRequest.onBeforeRequest.addListener(

  • 1) You probably see an old error. Click the trashcan icon to remove it and reload the extension. 2) `alert` doesn't work in ManifestV3 service worker. Use console.log and look at the [correct console](/a/10258029). 3) webRequest's redirectUrl requires `blocking` mode which won't work in a normal ManifestV3 extension, so you'll need to use declarativeNetRequest for redirection instead of webRequest. – wOxxOm Apr 19 '23 at 05:53

0 Answers0