I’m building a Chrome extension, manifest version 3, and grappling with declarativeNetRequest.
Desired behavior:
- User types in something like “go/blah” in their Chrome URL bar
- The pattern “go/*” triggers my Chrome extension, which can then process “blah” and do something with it
My manifest looks like this:
{
"name": "...",
"description": "...",
"version": "0.1",
"manifest_version": 3,
"background": {
"service_worker": "background.js"
},
"host_permissions": [
"*://*/*"
],
"declarative_net_request": {
"rule_resources": [
{
"id": "ruleset_1",
"enabled": true,
"path": "rules.json"
}
]
},
"permissions": [
"declarativeNetRequest",
"declarativeNetRequestWithHostAccess",
"declarativeNetRequestFeedback"
]
}
Here’s the rule I’m trying to use:
[
{
"id": 1,
"priority": 1,
"action": {
"type": "redirect",
"redirect": { "extensionPath": "/redirect.html" }
},
"condition": {
"urlFilter": "||go/*",
"resourceTypes": ["main_frame"]
}
}
]
First problem: this doesn’t trigger when I try to visit a page like “go/blah”. If I change the urlFilter to not have a wildcard, eg blahblah
, my Chrome extension does fire correctly
Second problem: even after the urlFilter is fixed, how can I access what filled in the wildcard, ie what came after go/
, in a script that’s in redirect.html?