使用 chrome.experimental.webRequest API 更改加载的文件?

发布于 2024-11-16 15:05:01 字数 498 浏览 2 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

友谊不毕业 2024-11-23 15:05:01

这是如何重定向特定 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']);

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']);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文