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
Post a Comment