在Chrome扩展程序中读取和修改HTTP GET请求 [英] Reading and modifying the HTTP GET request in a Chrome extension

查看:783
本文介绍了在Chrome扩展程序中读取和修改HTTP GET请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Chrome扩展程序中读取和修改(添加)HTTP标头.我使用的是chrome.webRequest API.但是我仍然无法阅读它.这是我的代码.

I would like to read and modify (add) HTTP headers in a Chrome extension. I am using the chrome.webRequest API for the same. But i am still not able to read it. Here's my code.

chrome.webRequest.onBeforeSendHeaders.addListener(

    function(details) {
    details.requestHeaders.push({name:"dummyHeader",value:"1"});
    return {requestHeaders: details.requestHeaders};
    },

    {urls: ["<all_urls>"]},
    ["requestHeaders"]

);

我想念什么?

推荐答案

您需要将"blocking"标志添加到ExtraInfoSpec列表中,以暂停请求.没有此标志,将忽略onBeforeSendHeaders事件侦听器的返回值.

You need to add the "blocking" flag to the ExtraInfoSpec list in order to pause the request. Without this flag, the return value of an onBeforeSendHeaders event listener is ignored.

chrome.webRequest.onBeforeSendHeaders.addListener(
    function(details) {
        details.requestHeaders.push({name:"dummyHeader",value:"1"});
        return {requestHeaders: details.requestHeaders};
    },
    {urls: ["<all_urls>"]},
    ["requestHeaders", "blocking"]
                      //^^^^^^^^
);

我建议您仔细阅读文档,尤其是注册事件监听器部分.

I suggest to read the documentation more carefully, in particular the Registering event listeners section.

这篇关于在Chrome扩展程序中读取和修改HTTP GET请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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