Blocking request in Chrome -


i'm trying block requests in chrome app.

i created javascript listener validation:

chrome.webrequest.onbeforerequest.addlistener(     {         urls: ["*://site.com/test/*"]     },     ["blocking"] ); 

but requests not blocking. did miss in code?

my manifest:

"background": {         "scripts": ["listener.js"],         "persistent": true     }, "permissions": ["tabs", "http://*/*"],     "manifest_version": 2, 

it looks misunderstood meaning of "blocking" here.

https://developer.chrome.com/extensions/webrequest.html#subscription

if optional opt_extrainfospec array contains string 'blocking' (only allowed specific events), callback function handled synchronously. means request blocked until callback function returns. in case, callback can return blockingresponse determines further life cycle of request.

to block request (cancel it), return {cancel: true} in event handler.

for example:

chrome.webrequest.onbeforerequest.addlistener(     function() {         return {cancel: true};     },     {         urls: ["*://site.com/test/*"]     },     ["blocking"] ); 

this block urls matching *://site.com/test/*.

also remember declare both webrequest , webrequestblocking permissions in manifest.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -