【问题标题】:Chrome Extension - webRequest listener not workingChrome 扩展 - webRequest 侦听器不起作用
【发布时间】:2015-12-07 10:21:06
【问题描述】:

我正在编写一个 Chrome 扩展程序,用于侦听 Google Docs 上的网络请求。我的所有代码大约在一周前工作,当我今天打开 Chrome 再次运行它时,我的 webRequest 侦听器不再起作用。

我可以看到请求通过,但“请求”从未打印到控制台。这是我的代码的问题吗?是否有新的 Chrome 更新导致此功能不再起作用?

Google Docs 页面(不是我的扩展程序的背景页面)的控制台中出现了一些错误,我也列出了它们。

背景.js:

chrome.webRequest.onBeforeRequest.addListener(
      function(request) {
          console.log("REQUEST");
          if (request.url.indexOf('/save?') != -1) {
            var requestBody = request.requestBody;
            var docId = request.url.match("docs\.google\.com\/document\/d\/(.*?)\/save")[1];
            var data = {
              "bundles": requestBody.formData.bundles,
              "timeStamp" : parseInt(request.timeStamp, 10)
            };
        parseData(data);
      }
    },
    { urls: ["*://*.google.com/*"] },
    ['requestBody']
);

manifest.json:

{
  "manifest_version": 2,
  "name": "Document Difficulty Prediction",
  "version": "0.1",
  "background": {
    "scripts": ["background.js"],
    "persistent": true
  },
  "permissions": [
    "webRequest",
    "activeTab",
    "*://*.google.com/"
   ]
}

docs.google.com 控制台中的错误列表:

GET chrome-extension://ghbmnnjooekpmoecnnnilnnbdlolhkhi/page_embed_script.js net::ERR_FAILED

jquery.min.js:3 在 docs.google.com/document/d/1tMzarhc5tqcMR8-Rpm_ukJ20pXK2jH8Ekub8HqHP_50/edit 中阻止脚本执行,因为文档的框架已被沙盒化并且未设置“允许脚本”权限。

未捕获的安全错误:阻止来自 clients5.google.com 的框架访问来自 docs.google.com 的框架。协议、域和端口必须匹配。

(错误消息中的所有三个链接前面都有 https://,但我不得不删除它,因为我没有足够的分数来在一个问题中包含三个链接)

【问题讨论】:

    标签: javascript google-chrome google-chrome-extension webrequest


    【解决方案1】:

    这是为了防止拦截对其他扩展程序和应用程序的请求而进行的修复的结果。他们还意外地阻止了托管应用程序。见crbug.com/510802#c60crbug.com/526413#c23

    【讨论】:

    • 谢谢!!那么当 bug 修复后,我的监听器应该可以再次工作了吗?
    • 您现在可以通过删除 Google Docs 托管应用来尝试。
    • Chrome 稳定版已更新至 45.0.2454.93,其中包含补丁。
    猜你喜欢
    • 2023-03-25
    • 2015-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-27
    • 1970-01-01
    相关资源
    最近更新 更多