我正在尝试使用 webRequest API 更改网页上加载的 .swf 文件...该页面加载一个名为 chat.swf 的文件,但我想重定向到同一目录中的 chat2.swf 以便使用另一个文件。有人告诉我这可行,但我不知道如何正确使用这个 API,而且我找不到任何示例@_@
function incerceptChat(chat){
console.log( "onBeforeRequest", details );
if(chat.url == swf1){
chat = swf2;
}
}
这是我应该更改 URL 的函数,但我无法让它工作(可能是某个地方的语法错误......),我用它来监听:
chrome.experimental.webRequest.onBeforeRequrest.addListener(interceptChat, {"redirectUrl": chat});
这是如何重定向特定 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']);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)