I want to ensure uniqueness of IDs of 2(or more) declarativeNetRequest rules applied on a single tab.
These rules can be applied in multiple tabs.(based on certain dynamic logic)
So rule they cannot be applied using condition:tabIds as each rule’s action varies.
Now I have to use integer for this .
What can be done to ensure unique ids. Since its not clear from the docs that what logic chrome uses to assign tabsIds. So cannot do something like
Rule 1 – tabId
Rule 2 – tabId *1000 (ids may collide).
Is there a fool proof logic . Esentially I want to have non-persistent tab scoped rules.
Note : I don’t care about deleting these rules as they are supposed to remain as long as the tab is “alive”.
inside chrome.tabs.onUpdated we are doing certain calculations based on the URLs of the tabs opened and deciding rules to apply to certain tabs
chrome.tabs.onUpdated.addEvenetListener(function(tabId,details)
{
const val = //some logic that uses currently opened tabs info and does some calculations
const dynamicallyCreatedRules ={
id: tabID,
priority: 1,
condition: {
tabIds: [tabID],
requestDomains:[...domains1]
},
action: {
type: "modifyHeaders",
responseHeaders: [
{ header: "Access-Control-Allow-Headers", operation: "set", value: dynamicOriginValue(val) },
]
}
},{
id: tabID*10000000,//might conflict with other rules
priority: 1,
condition: {
tabIds: [tabID],
requestDomains:[...domains2]
},
action: {
type: "modifyHeaders",
responseHeaders: [
{ header: "something", operation: "set", value: dynamicLogic(val)},
]
}
},
chrome.declarativeNetRequest.updateSessionRules(dynamicallyCreatedRules)
}
I was thinking of having a rule counter for the Id c=0 and everytime I add a rule I just do c++. But what if a chrome tab ID has the same value as the counter value.