The-CodingSloth / haha-funny-leetcode-extension

MIT License
396 stars 75 forks source link

the redirect rule does not work on firefox #34

Closed The-CodingSloth closed 10 months ago

The-CodingSloth commented 10 months ago

Was working on trying to get it to work on firefox, and have this issue:

async function setRedirectRule(newRedirectUrl: string) {
  let newRedirectRule = {
    id: RULE_ID,
    priority: 1,
    action: {
      type: "redirect",
      redirect: { url: newRedirectUrl }
    },
    condition: {
      urlFilter: "*://*/*",
      excludedInitiatorDomains: [
        "leetcode.com",
        "www.leetcode.com",
        "developer.chrome.com"
      ],

      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)
  }
}

For some reason the new rule gets updated in chrome, but not in firefox. When I console log currentRules it shows an empty array on firefox, when it should be showing the rule inside of the array. If anyone knows why or can fix this, that'd be awesome and you're better than me

green1490 commented 10 months ago

There is 2 possible case here. The first is that there is no active rule or you are using the wrong object.

The-CodingSloth commented 10 months ago

hmmm, I'm just having general problems using this on firefox for some reason the chrome.runtime.getURL works, the storage works, opening a new tab works, but some of the other chrome listeners like onCompleted and this declarativeNetRequest aren't. Might be an issue with this framework or I'm just dumb. They say using the chrome APIs should also work on firefox with their framework.

green1490 commented 10 months ago

Are you giving them the proper permissions in your manifest.json?

The-CodingSloth commented 10 months ago

Yeah I think so, I'm gonna open a new branch for this if anyone wants to figure this out or see what's going on.

green1490 commented 10 months ago

image

The-CodingSloth commented 10 months ago

LOL whoops