Answer the question
In order to leave comments, you need to log in
Intercepting requests with "JS" in "Chrome"?
Good afternoon. Can anyone tell me how to intercept requests using JS in "Chrome"?
For example, so that for any request to some or all sites, the string "this is a response constructed by VPN extension" is returned to me.
Answer the question
In order to leave comments, you need to log in
If I understand correctly that you have your own extension, then:
Edit the manifest by adding "webRequest" to the permissions
"permissions": [
"webRequest"
// other permissions
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
if (details.url.indexOf("://white.listed.site")) console.log("this is a response constructed by VPN extension");
return {cancel: details.url.indexOf("://www.evil.com/") != -1}; // если нужно отменить запрос
},
{urls: ["<all_urls>"]},
["blocking"]);
chrome.webRequest.onCompleted.addListener(function(details){
console.log(`Catch ${details.method} response from ${details.url} ${details.fromCache ? ' [ from cache ]' : ''} `)
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question