1. <legend id='GQu5A'><style id='GQu5A'><dir id='GQu5A'><q id='GQu5A'></q></dir></style></legend>

      <small id='GQu5A'></small><noframes id='GQu5A'>

    2. <i id='GQu5A'><tr id='GQu5A'><dt id='GQu5A'><q id='GQu5A'><span id='GQu5A'><b id='GQu5A'><form id='GQu5A'><ins id='GQu5A'></ins><ul id='GQu5A'></ul><sub id='GQu5A'></sub></form><legend id='GQu5A'></legend><bdo id='GQu5A'><pre id='GQu5A'><center id='GQu5A'></center></pre></bdo></b><th id='GQu5A'></th></span></q></dt></tr></i><div id='GQu5A'><tfoot id='GQu5A'></tfoot><dl id='GQu5A'><fieldset id='GQu5A'></fieldset></dl></div>
    3. <tfoot id='GQu5A'></tfoot>
        <bdo id='GQu5A'></bdo><ul id='GQu5A'></ul>
    4. webRequest 侦听器看不到“cookie"、“referer"、“origin"等

      webRequest listener doesn#39;t see headers like #39;cookie#39;, #39;referer#39;, #39;origin#39;(webRequest 侦听器看不到“cookie、“referer、“origin等标头)
        <tbody id='zmHOL'></tbody>
    5. <i id='zmHOL'><tr id='zmHOL'><dt id='zmHOL'><q id='zmHOL'><span id='zmHOL'><b id='zmHOL'><form id='zmHOL'><ins id='zmHOL'></ins><ul id='zmHOL'></ul><sub id='zmHOL'></sub></form><legend id='zmHOL'></legend><bdo id='zmHOL'><pre id='zmHOL'><center id='zmHOL'></center></pre></bdo></b><th id='zmHOL'></th></span></q></dt></tr></i><div id='zmHOL'><tfoot id='zmHOL'></tfoot><dl id='zmHOL'><fieldset id='zmHOL'></fieldset></dl></div>

        <legend id='zmHOL'><style id='zmHOL'><dir id='zmHOL'><q id='zmHOL'></q></dir></style></legend>

          <tfoot id='zmHOL'></tfoot>
          1. <small id='zmHOL'></small><noframes id='zmHOL'>

                <bdo id='zmHOL'></bdo><ul id='zmHOL'></ul>
                本文介绍了webRequest 侦听器看不到“cookie"、“referer"、“origin"等标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我们编写了一个 Chrome 扩展,它使用 onBeforeSendHeaders 事件为每个 Web 请求添加一个 cookie:

                chrome.webRequest.onBeforeSendHeaders.addListener(addCookie, {网址:["<all_urls>"]}, ["blocking", "requestHeaders"]);功能 addCookie(详细信息){if (details.url.match(/ourWebsite/)) {details.requestHeaders.forEach(function (requestHeader) {if (requestHeader.name.toLowerCase() === "cookie") {//添加带有值的cookie的代码}});返回 {requestHeaders: details.requestHeaders};}}

                除了我自己的以外,它在每个人的 Chrome 上都可以正常工作.在调试扩展时,我注意到 details.requestHeaders 数组没有 cookie 标头(这总是错误的:requestHeader.name.toLowerCase()=== "cookie").

                我的第一个想法是另一个扩展程序搞砸了我们的,所以我尝试隐身(不允许其他扩展程序)但它不起作用.

                在扩展程序的清单中,我们在 permissions 下同时拥有cookies"和webRequest".

                有什么想法吗?提前致谢!

                解决方案

                据此https://developer.chrome.com/extensions/webRequest

                <块引用>
                • 从 Chrome 72 开始,不提供以下请求标头,并且如果未在 opt_extraInfoSpec 中指定extraHeaders",则无法修改或删除:

                  • 接受语言
                  • 接受编码
                  • 推荐人
                  • Cookie
                • 自 Chrome 79 起:

                  • 原产地
                  • CORS 预检请求

                <块引用>

                其他侦听器的响应标头,例如 onHeadersReceived:

                • 自 Chrome 72 起:
                  • 设置-Cookie
                  • 您想要在 CORB 已应用
                • 自 Chrome 79 起:
                  • CORS 预检响应

                所以你应该添加extraHeaders";到 webRequest 侦听器的第三个参数,对于您的示例,它应该是 [blocking", requestHeaders", extraHeaders"].

                请注意,它不会在不了解 extraHeaders 的旧的 pre-72 Chrome 中运行,因此您可以使用以下技巧来拥有一个通用兼容的侦听器:

                chrome.webRequest.onBeforeSendHeaders.addListener(添加Cookie,{urls: ["<all_urls>"]},[阻塞",请求标头",chrome.webRequest.OnBeforeSendHeadersOptions.EXTRA_HEADERS].filter(Boolean));

                We wrote a Chrome-extension that, using the onBeforeSendHeaders event, adds a cookie to each web request:

                chrome.webRequest.onBeforeSendHeaders.addListener(addCookie, {
                    urls: ["<all_urls>"]
                }, ["blocking", "requestHeaders"]);
                
                function addCookie(details) {
                    if (details.url.match(/ourWebsite/)) {
                        details.requestHeaders.forEach(function (requestHeader) {
                            if (requestHeader.name.toLowerCase() === "cookie") {
                                //Code that adds a cookie with a value
                            }
                        });
                        return {requestHeaders: details.requestHeaders};
                    }
                }
                

                It works fine on everyone's Chrome but my own. While debugging the extension, I noticed that the details.requestHeaders array doesn't have the cookie header (this is always false: requestHeader.name.toLowerCase() === "cookie").

                My first thought was another extension is messing up with ours, so I tried in incognito (where no other extensions are allowed) but it didn't work.

                In the extension's manifest we have both "cookies" and "webRequest" under permissions.

                Any ideas? Thanks in advance!

                解决方案

                According to this https://developer.chrome.com/extensions/webRequest

                • Starting from Chrome 72, the following request headers are not provided and cannot be modified or removed without specifying 'extraHeaders' in opt_extraInfoSpec:

                  • Accept-Language
                  • Accept-Encoding
                  • Referer
                  • Cookie
                • since Chrome 79:

                  • Origin
                  • CORS preflight requests

                Response headers for other listeners like onHeadersReceived:

                • since Chrome 72:
                  • Set-Cookie
                  • any header you want to modify before CORB is applied
                • since Chrome 79:
                  • CORS preflight responses

                So you should add "extraHeaders" to the third parameter of the webRequest listener and it should be ["blocking", "requestHeaders", "extraHeaders"] for your example.

                Note that it won't run in old pre-72 Chrome, which doesn't know about extraHeaders, so you can use the following trick to have a universally compatible listener:

                chrome.webRequest.onBeforeSendHeaders.addListener(
                  addCookie,
                  {urls: ["<all_urls>"]},
                  ["blocking", "requestHeaders",
                   chrome.webRequest.OnBeforeSendHeadersOptions.EXTRA_HEADERS].filter(Boolean)
                );
                

                这篇关于webRequest 侦听器看不到“cookie"、“referer"、“origin"等标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                quot;Status Code:200 OK (from ServiceWorker)quot; in Chrome Network DevTools?(“状态码:200 OK(来自 ServiceWorker)在 Chrome 网络开发工具中?)
                How to set a header for a HTTP GET request, and trigger file download?(如何为 HTTP GET 请求设置标头并触发文件下载?)
                Adding custom HTTP headers using JavaScript(使用 JavaScript 添加自定义 HTTP 标头)
                SQL Query DocumentDB in Azure Functions by an integer not working(通过整数在 Azure Functions 中 SQL 查询 DocumentDB 不起作用)
                Azure Functions [JavaScript / Node.js] - HTTP call, good practices(Azure Functions [JavaScript/Node.js] - HTTP 调用,良好实践)
                Azure Functions - Import Custom Node Module(Azure Functions - 导入自定义节点模块)
                • <i id='BBaMx'><tr id='BBaMx'><dt id='BBaMx'><q id='BBaMx'><span id='BBaMx'><b id='BBaMx'><form id='BBaMx'><ins id='BBaMx'></ins><ul id='BBaMx'></ul><sub id='BBaMx'></sub></form><legend id='BBaMx'></legend><bdo id='BBaMx'><pre id='BBaMx'><center id='BBaMx'></center></pre></bdo></b><th id='BBaMx'></th></span></q></dt></tr></i><div id='BBaMx'><tfoot id='BBaMx'></tfoot><dl id='BBaMx'><fieldset id='BBaMx'></fieldset></dl></div>
                • <tfoot id='BBaMx'></tfoot>
                • <small id='BBaMx'></small><noframes id='BBaMx'>

                      <legend id='BBaMx'><style id='BBaMx'><dir id='BBaMx'><q id='BBaMx'></q></dir></style></legend>

                          <bdo id='BBaMx'></bdo><ul id='BBaMx'></ul>

                            <tbody id='BBaMx'></tbody>