I’m updating a browser extension from Manifest v2 to v3 and have therefore implemented dynamic rules as follows:
const extensionUrl = chrome.runtime.getURL('/content/redirect.html');
chrome.declarativeNetRequest.updateDynamicRules({
removeRuleIds: [ 1 ],
addRules: [
{
action: {
type: 'redirect',
redirect: {
regexSubstitution: `${extensionUrl}?\\1`
}
},
condition: {
regexFilter: '^https:\\/\\/mail\\.google\\.com\\/mail\\/\\?(affixa=.*)',
resourceTypes: [ 'main_frame' ]
},
id: 1,
priority: 1
}
]
});
In Chrome (131) when executed as a service worker, a URL such as the following is handled by the above rule - i.e. it is redirected to a page within the extension and includes the querystring in the URL.
https://mail.google.com/mail/?affixa=-1225818694#drafts/?compose=GTvVlcSMSqLWmXnCXpcwWVXqTKRWNQfQMTXdlQtCtTthzDfGrcgcdrdfqCLXqwtmhTMwGlQGWDKtB
In Firefox (132) when executed as a background page, nothing happens at all. No redirect happens and neither does the browser navigate to the original URL. All that does happen is, if I open a new tab, enter the above URL and press enter, any home screen content such as search box, news stories, etc, disappears and I get an empty screen. There’s no errors in the console for that tab, no errors when inspecting the background page, etc.
If I manually enter the address that the browser should have redirected to:
moz-extension://1c15cdd3-8b1e-435b-8e91-c9fa44dc64b2/content/redirect.html?affixa=-1225818694#drafts/?compose=GTvVlcSMSqLWmXnCXpcwWVXqTKRWNQfQMTXdlQtCtTthzDfGrcgcdrdfqCLXqwtmhTMwGlQGWDKtB
the page works absolutely fine and completes the use case its designed to do.
Can anybody suggest what might be going wrong here?
The pertinent bits of my manifest file are as follows:
"host_permissions": [
"*://mail.google.com/*",
"*://accounts.google.com/*"
],
"permissions": [
"alarms",
"declarativeNetRequest",
"storage",
"tabs",
"webRequest"
],
The extension has been loaded unpacked using about:debugging
.
Thanks in advance!
Chris