Using the chrome.experimental.webRequest API to modify the downloaded file?

I am trying to use the webRequest API to modify a downloaded .swf file on a web page ... The page loads a file called chat.swf, but I want to redirect to chat2.swf in the same directory to use a different file. I was told that this might work, but I have no idea how to use this API correctly, and I cannot find examples @_ @

function incerceptChat(chat){
    console.log( "onBeforeRequest", details );
        if(chat.url == swf1){
            chat = swf2;
        }
}

that is my function, which should change the url, but I was not able to get it to work (maybe the wrong syntax is somewhere ...), and I use this to listen:

chrome.experimental.webRequest.onBeforeRequrest.addListener(interceptChat, {"redirectUrl": chat});
+3
source share
1 answer

These are the basic principles for redirecting a specific URL.

function interceptRequest(request) {
  console.log('onBeforeRequest ', request.url);
  if (request && request.url && request.url === 'http://example.org/') {
    return { redirectUrl: 'http://www.google.com' }
  }
}
chrome.experimental.webRequest.onBeforeRequest.addListener(interceptRequest, null, ['blocking']);

null , URL, Chrome , JS . , , , -.

function interceptRequest(request) {
  return { redirectUrl: 'http://example.com/chat2.swf' }
}
chrome.experimental.webRequest.onBeforeRequest.addListener(interceptRequest, { urls: ['http://example.com/swf'] }, ['blocking']);
+5

All Articles