Bug
Core Api docs: declarativeNetRequest.Rule - Mozilla | MDN
This code is very simple, with only two rules:
- redirects the website to
?target=t
- modifies the website’s request header to add
h2=h2
h3=h3
But only 1 or 2 is effective, they cannot both be effective at the same time, while in Chrome, they can be effective simultaneously and work normally.
In manifest.json
, it is specified that the above rules are only effective for https://www.amazon.com/*.
manifest.json
{
"manifest_version": 3,
"name": "test",
"author": "lqzh",
"homepage_url": "https://github.com/test",
"version": "1.0.1",
"description": "test",
"permissions": [
"declarativeNetRequest"
],
"declarative_net_request": {
"rule_resources": [
{
"id": "rules",
"enabled": true,
"path": "rules.json"
}
]
},
"icons": {
"16": "./icons/icon_16.png",
"32": "./icons/icon_32.png",
"48": "./icons/icon_48.png",
"128": "./icons/icon_128.png"
},
"host_permissions": [
"https://www.amazon.com/*"
],
"minimum_chrome_version": "101"
}
rules.json
[
{
"id": 1,
"priority": 1,
"action": {
"type": "redirect",
"redirect": {
"transform": {
"queryTransform": {
"addOrReplaceParams": [
{
"key": "target",
"value": "t"
}
]
}
}
}
},
"condition": {
"urlFilter": "*",
"resourceTypes": [
"main_frame",
"sub_frame",
"stylesheet",
"script",
"image",
"font",
"object",
"xmlhttprequest",
"ping",
"csp_report",
"media",
"websocket",
"other"
]
}
},
{
"id": 2,
"priority": 2,
"action": {
"type": "modifyHeaders",
"requestHeaders": [
{
"operation": "set",
"header": "h2",
"value": "h2"
},
{
"operation": "set",
"header": "h3",
"value": "h3"
}
]
},
"condition": {
"urlFilter": "*",
"resourceTypes": [
"main_frame",
"sub_frame",
"stylesheet",
"script",
"image",
"font",
"object",
"xmlhttprequest",
"ping",
"csp_report",
"media",
"websocket",
"other"
]
}
}
]