google-chrome - 在加载前用不同的 url 替换 url

标签 google-chrome google-chrome-extension

在 google chrome 扩展中,如何在加载之前用不同的 URL 替换请求 URL?

我看了chrome.webRequest我认为其中之一就是我正在寻找的,我不知道究竟是哪一个。我相信谷歌限制了某种东西,不确定这是否是其中之一。

最佳答案

我找到了一个这样做的例子:

chrome.webRequest.onBeforeRequest.addListener(
  function(info) {
    // Redirect the original request to a given URL.
    var url = "http://site.com/image.png";
    return {redirectUrl: url};
  },
  // filters
  {
    urls: [
      "http://original.com/*"
    ],
    types: ["image"]
  },
  // extraInfoSpec
  ["blocking"]);

关于google-chrome - 在加载前用不同的 url 替换 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13944730/

相关文章:

javascript - 如何保存Chrome的Coverage工具分析的结果?

google-chrome-extension - Chrome 书签 API -

google-chrome - 在不重新安装的情况下更新 chrome 中的油脂猴脚本?

javascript - 我无法使 "commands"在 chrome 扩展中工作

javascript - Forefox 和 Chrome 之间的 HTMLCollection.namedItem() 行为差异?

google-chrome - 在 Firefox/Chrome devtools 中有没有办法在连接后发送/编辑 websocket 消息

javascript - 向下滚动时,Chrome(在 Android 上)地址栏不会消失

html - 谷歌浏览器切断长页面的底部

javascript - 在 Chrome 扩展中使用 AngularJS

javascript - Chrome 扩展 "Refused to load the script because it violates the following Content Security Policy directive"