在 Chrome 中加载 analytics.js 时发生 307 重定向 [英] 307 Redirect when loading analytics.js in Chrome

查看:44
本文介绍了在 Chrome 中加载 analytics.js 时发生 307 重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个网络应用并使用 Google Analytics (analytics.js) 进行分析.我最近注意到 Chrome 中的分析无法正常工作.

我正在使用单独模块中的标准代码片段加载分析,并通过 requirejs 包含在内.我已验证此脚本按预期运行并执行分析代码段.

当我在 Firefox 中检查网络流量时,我可以看到分析脚本按预期从 Google 加载(HTTP 200 响应):

但是,当我在 Chrome 中运行完全相同的页面时,我收到指向 about:blank 的 HTTP 307 响应,并且分析没有运行:

但是,如果我将分析 URL 直接粘贴到 Chrome 地址栏中,则会找到该脚本.任何想法这里发生了什么,或者如何解决它?

解决方案

307 Internal Redirect with Non-Authorative-Reason: Delegate 表示请求被拦截修改(重定向)由 Chrome 扩展程序通过 webRequestdeclarative webRequest 扩展 API.

您可以通过以下方式找出触发重定向的扩展程序:

  1. 访问 chrome://net-internals/#events
  2. 触发请求(谷歌分析,在你的情况下).
  3. 返回 chrome://net-internals/#events 标签并查找与您的请求匹配的 URL_REQUEST(您可以使用搜索框过滤搜索).
  4. 单击条目以在右侧显示日志.您将看到有关请求的扩展名、扩展名和其他信息:

<前>t=7910 [st=0] +REQUEST_ALIVE [dt=6]t=7910 [st=0] +URL_REQUEST_DELEGATE [dt=5]t=7910 [st=0] DELEGATE_INFO [dt=5] --> delegate_info = "extension [扩展名]"t=7915 [st=5] CHROME_EXTENSION_REDIRECTED_REQUEST--> extension_id = "ebmlimjkpnhckbaejoagnjlgcdhdnjlb"t=7915 [st=5] -URL_REQUEST_DELEGATEt=7915 [st=5] +URL_REQUEST_START_JOB [dt=1]--> load_flags = 339804160 (BYPASS_DATA_REDUCTION_PROXY | MAYBE_USER_GESTURE | REPORT_RAW_HEADERS | VERIFY_EV_CERT)--> 方法 = "GET"--> 优先级 = "低" --> url = "https://www.google-analytics.com/analytics.js"t=7915 [st=5] URL_REQUEST_REDIRECT_JOB--> 原因 = "委托"t=7915 [st=5] URL_REQUEST_FAKE_RESPONSE_HEADERS_CREATED--> HTTP/1.1 307 内部重定向位置:关于:空白非权威理由:委托

在此日志示例中,名称为[Name of extension]"且扩展 ID 为ebmlimjkpnhckbaejoagnjlgcdhdnjlb"的扩展重定向了请求.找到扩展程序名称和/或 ID 后,您可以访问 chrome://extensions 并禁用或删除修改请求的扩展程序.

I'm building a web app and using Google Analytics (analytics.js) for analytics. I recently noticed that analytics aren't working properly in Chrome.

I'm loading analytics using the standard code snippet in a separate module and included via requirejs. I've verified that this script runs as expected and executes the analytics snippet.

When I inspect network traffic in Firefox, I can see that the analytics script is loaded from Google as expected (HTTP 200 response):

However, when I run the exact same page in Chrome, I get an HTTP 307 response pointing to about:blank, and analytics does not run:

However, if I paste the analytics URL directly into the Chrome address bar, the script is found. Any ideas what's going on here, or how to fix it?

解决方案

307 Internal Redirect with Non-Authorative-Reason: Delegate indicates that the request was intercepted and modified (redirected) by a Chrome extension via the webRequest or declarative webRequest extension APIs.

You can find out which extension triggered the redirect as follows:

  1. Visit chrome://net-internals/#events
  2. Trigger the request (google analytics, in your case).
  3. Go back to the chrome://net-internals/#events tab and look for a URL_REQUEST matching your request (you can use the searchbox to filter the search).
  4. Click on the entry to show the log at the right side. You will see the extension name, extension ID and other information about the request:

t=7910 [st=0] +REQUEST_ALIVE  [dt=6]
t=7910 [st=0]   +URL_REQUEST_DELEGATE  [dt=5]
t=7910 [st=0]      DELEGATE_INFO  [dt=5]
                   --> delegate_info = "extension [Name of extension]"
t=7915 [st=5]      CHROME_EXTENSION_REDIRECTED_REQUEST
                   --> extension_id = "ebmlimjkpnhckbaejoagnjlgcdhdnjlb"
t=7915 [st=5]   -URL_REQUEST_DELEGATE
t=7915 [st=5]   +URL_REQUEST_START_JOB  [dt=1]
                 --> load_flags = 339804160 (BYPASS_DATA_REDUCTION_PROXY | MAYBE_USER_GESTURE | REPORT_RAW_HEADERS | VERIFY_EV_CERT)
                 --> method = "GET"
                 --> priority = "LOW"
                 --> url = "https://www.google-analytics.com/analytics.js"
t=7915 [st=5]      URL_REQUEST_REDIRECT_JOB
                   --> reason = "Delegate"
t=7915 [st=5]      URL_REQUEST_FAKE_RESPONSE_HEADERS_CREATED
                   --> HTTP/1.1 307 Internal Redirect
                       Location: about:blank
                       Non-Authoritative-Reason: Delegate

In this log sample, an extension with name "[Name of extension]" and extension ID "ebmlimjkpnhckbaejoagnjlgcdhdnjlb" redirected the request. After finding the extension name and/or ID, you can visit chrome://extensions and disable or remove the extension that modified the request.

这篇关于在 Chrome 中加载 analytics.js 时发生 307 重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆