The Coding Sloth
The Coding Sloth
PD🧩 Plasmo Developers
Created by The Coding Sloth on 9/9/2023 in #👟framework
declarativeNetRequest
I want to use the declarativeNetRequest API, and I have it working for chrome, but when I test it on firefox, its not working:
async function setRedirectRule(newRedirectUrl: string) {
let newRedirectRule = {
id: RULE_ID,
priority: 1,
action: {
type: "redirect",
redirect: { url: newRedirectUrl }
},
condition: {
urlFilter: "*://*/*",

resourceTypes: ["main_frame"]
}
}

try {
chrome.declarativeNetRequest.updateDynamicRules({
removeRuleIds: [RULE_ID],
addRules: [newRedirectRule]
})
const currentRules = await chrome.declarativeNetRequest.getDynamicRules()
console.log("Redirect rule updated")
console.log("Current rules:", currentRules)
} catch (error) {
console.error("Error updating redirect rule:", error)
}
}
async function setRedirectRule(newRedirectUrl: string) {
let newRedirectRule = {
id: RULE_ID,
priority: 1,
action: {
type: "redirect",
redirect: { url: newRedirectUrl }
},
condition: {
urlFilter: "*://*/*",

resourceTypes: ["main_frame"]
}
}

try {
chrome.declarativeNetRequest.updateDynamicRules({
removeRuleIds: [RULE_ID],
addRules: [newRedirectRule]
})
const currentRules = await chrome.declarativeNetRequest.getDynamicRules()
console.log("Redirect rule updated")
console.log("Current rules:", currentRules)
} catch (error) {
console.error("Error updating redirect rule:", error)
}
}
On chrome the new rule appears when I log currentRules, but on Firefox it's empty, not sure why it's not updating.
15 replies