Reputation: 58
I don't get the {urls: ["://www.mysite.com/.js"]}, ["blocking"]); part. This code can be found @ Chrome extension to modify page's script includes and JS with the slight (forced) modification of mysite(dot)com to example.com due to stackoverflow rules.
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
if( details.url == "http://www.example.com/js/library.js" )
return {redirectUrl: "http://www.example.com/js/library_dev.js" };
},
{urls: ["*://www.example.com/*.js"]},
["blocking"]);
Upvotes: 1
Views: 118
Reputation: 553
The second parameter of onBeforeRequest.addEventListener
is an optional requestFilter object.
It has four additional properties
So urls: ["*://www.example.com/*.js"]}
is adding a URL filter to the onBeforeRequest listener.
This is attempt to match any request for a javascript file on the www.example.com domain. Using http or https
[(scheme) *] :\\ [(host) www.example.com] / [(path) *.js]
<url-pattern> := <scheme>://<host><path>
<scheme> := '*' | 'http' | 'https' | 'file' | 'ftp'
<host> := '*' | '*.' <any char except '/' and '*'>+
<path> := '/' <any chars>
https://developer.chrome.com/extensions/match_patterns
The third parameter ['blocking']
is an optional array of strings used for extra information. This modifies how Chrome returns your callback.
Since it contains "blocking", the callback function is handled synchronously. That means that the request is blocked until the callback function returns. So for onBeforeRequest you could use this to cancel or redirect a request before it happens.
More info available here:
Upvotes: 1