使用 chrome.experimental.webRequest API 更改加载的文件?
我正在尝试使用 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});
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});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是如何重定向特定 URL 的基础知识。
您还可以将
null
替换为进一步限制 URL 匹配的对象,因为 Chrome 会比使用 JS 执行更高的性能。但请注意不要过于贪婪地重定向,因为这可能会导致一般网络浏览出现问题。This is the basics of how to redirect a specific URL.
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.