I’m trying to write a chrome extension that routes certain requests to another. I’ve found a couple resources on how to do that and I’ve gotten it half working. Here is the extension code:
var requestRoutingTable = {
'some/url/i/want/to/catch' : 'libs/TVKeyValue.js'
};
chrome.webRequest.onBeforeRequest.addListener(function(details){
for (var key in requestRoutingTable){
if (details.url.indexOf(key) != -1){
console.log('redirecting to: ' + chrome.extension.getURL(requestRoutingTable[key]));
return {redirectUrl: chrome.extension.getURL(requestRoutingTable[key])};
}
}
}, {urls: ["<all_urls>"]}, ["blocking"]);
To test whether this works, I wrote the following in jQuery and loaded the extension:
$.getScript('some/url/i/want/to/catch', function(script, textStatus, jqXHR){
// this doesn't get here!
}
Symptoms:
- I see that the console.log from the extension code gets triggered
- I see that the actual file get loaded through the chrome extension (through the network tab in the developer tools
Problems:
The callback doesn’t get triggered. Suspiciously, the original request stays in the “pending” status.
The point of this extension is to place some stubs/mock responses for certain requests. Am I missing something?
I believe this may be an issue with Chrome extensions, I have reported it as a possible bug here:
http://code.google.com/p/chromium/issues/detail?id=145074