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(