当前位置: 首页 > news >正文

chrome extension插件替换网络请求中的useragent

感觉Chrome商店中的插件不能很好的实现自己想要的效果,那么就来自己动手吧。
本文以百度为例:

一般来说网页请求如下:

请添加图片描述

当前使用的useragent是User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
s

需要把这个给换点,查了很久的Chrome的文档,看到有个相关的说明,找了个比较靠谱的,经过很多的尝试终于试验成功了。

本例子使用的 mainfest v3,查了很多的文档说的是使用的 webRequestBlocking 这个权限跟API,但是开头就有如下的问题描述。

Note: As of Manifest V3, the “webRequestBlocking” permission is no longer available for most extensions. Consider “declarativeNetRequest”, which enables use the declarativeNetRequest API. Aside from “webRequestBlocking”, the webRequest API is unchanged and available for normal use. Policy installed extensions can continue to use “webRequestBlocking”.

依照文档,之前老的 block 被弃用了,需要使用新的 declarativeNetRequest 方式, 文档地址https://developer.chrome.com/docs/extensions/reference/api/declarativeNetRequest

其中的规则包含很多种:

  1. “block” Block the network request.
  2. “redirect” Redirect the network request.
  3. “allow” Allow the network request. The request won’t be intercepted if there is an allow rule which matches it.
  4. “upgradeScheme” Upgrade the network request url’s scheme to https if the request is http or ftp.
  5. “modifyHeaders” Modify request/response headers from the network request.
  6. “allowAllRequests”
    Allow all requests within a frame hierarchy, including the frame request itself.

感觉这个 modifyHeaders 还挺靠谱的。然后看到如下有一个看起来可以用的例子,

{"id"
http://www.lryc.cn/news/344199.html

相关文章:

  • PHP基础【介绍,注释,更改编码,赋值,数据类型】
  • ASP.NET小型证券术语解释及翻译系统的设计与开发
  • 硬件知识积累 音频插座的了解,看音频插座的原理图来了解音频插座的引脚。
  • error LNK2001: 无法解析的外部符号 “__declspec(dllimport) public: __cdecl ......
  • 邮箱Webhook API发送邮件的性能怎么优化?
  • 并发编程实现
  • 基于EBAZ4205矿板的图像处理:12图像二值化(阈值可调)
  • 人大金仓数据库报com.kingbase8.util.KSQLException: 致命错误: 用户 “SYSTEM“ Password 认证失败
  • 文件加密软件哪个好?文件加密软件排行榜前十名(好用软件推荐)
  • Netty的第一个简单Demo实现
  • K8S 哲学 - 服务发现 services
  • Springboot工程创建
  • 日本站群服务器的优点以及适合该服务器的业务类型?
  • 堆的应用2——TOPK问题
  • leetcode-5. 最长回文子串
  • 【Flask 系统教程 1】入门及配置
  • 石家庄河北银行的
  • 【CCNP ENCOR OCG】CHAPTER 2》Spanning Tree Protocol
  • docker无法映射/挂载根目录
  • C++中不要重新定义继承而来的non-virtual函数
  • C++ 对象型参数和返回值
  • LeetCode 字符串专题——KMP算法_28. 找出字符串中第一个匹配项的下标
  • 上班不想用脑子写代码了怎么办?那就试试Baidu Comate啊宝贝
  • 【管理咨询宝藏94】某国际咨询公司供应链财务数字化转型方案
  • C++_使用邻接表(链表-指针)实现有向图[完整示例及解释]
  • Gitlab自动化测试的配置
  • Qwen-Audio:推动通用音频理解的统一大规模音频-语言模型(开源)
  • 杭州破冰之举:全面取消住房限购,激发市场新活力
  • ICode国际青少年编程竞赛- Python-1级训练场-变量练习
  • 学习STM32第二十天