使用chrome.experimental.webRequest API更改加载文件? [英] using chrome.experimental.webRequest API to change loaded file?

查看:469
本文介绍了使用chrome.experimental.webRequest API更改加载文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用的WebRequest API改变加载的.swf文件的网页文件...页面加载一个名为chat​​.swf文件,但我想重定向在同一目录下chat2.swf以使用其他的文件。有人告诉我,这可能是工作,但我不知道如何正确使用这个API,我无法找到任何的例子!@ _ @

 函数incerceptChat(聊天){
    的console.log(onBeforeRequest,详细说明);
        如果(chat.url == SWF1){
            聊天= swf2;
        }
}

这是我的函数,是应该更改URL,但我一直无法得到它的工作(可能是错误的语法某处...),我用这个听:

  chrome.experimental.webRequest.onBeforeRequrest.addListener(interceptChat,{的redirectUrl:聊天});


解决方案

这是如何重定向特定的URL的基本知识。

 函数interceptRequest(要求){
  的console.log('onBeforeRequest',request.url);
  如果(请求&安培;&安培; request.url和放大器;&安培; request.url ===htt​​p://example.org/'){
    返回{的redirectUrl:http://www.google.com'}
  }
}
chrome.experimental.webRequest.onBeforeRequest.addListener(interceptRequest,空,['堵']);

您还可以进一步限制URL匹配的Chrome将是更好的性能则有JS做一个对象替换。要小心,不要在您重定向虽然什么太贪婪因为这可能会导致一般的网页浏览的问题。

 函数interceptRequest(要求){
  返回{的redirectUrl:http://example.com/chat2.swf'}
}
chrome.experimental.webRequest.onBeforeRequest.addListener(interceptRequest,{网址:['http://example.com/swf']},['堵']);

I'm trying to use webRequest API to change the loaded .swf file on a webpage... The page loads a file called chat.swf, but i want to redirect to chat2.swf in the same directory in order to use the other file. I was told that this could work, but I have no idea how to use this API correctly and I cannot find any examples @_@

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

that's my function that's supposed to change the URL, but I have been unable to get it to work (probably wrong syntax somewhere...) and I'm using this to listen:

chrome.experimental.webRequest.onBeforeRequrest.addListener(interceptChat, {"redirectUrl": chat});

解决方案

This is the basics of how to redirect 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']);

You can also replace null with an object that further restricts the URL matching as Chrome will be more performant then having JS do it. Be careful not to be too greedy in what you redirect though as that can cause issues with general web browsing.

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

这篇关于使用chrome.experimental.webRequest API更改加载文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆