Skip to content

Commit

Permalink
fix: use alarms to remove declarativeNetRequest session rules
Browse files Browse the repository at this point in the history
  • Loading branch information
dessant committed Oct 31, 2023
1 parent be031ea commit 941d1ee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
16 changes: 10 additions & 6 deletions src/background/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
isAndroid,
isMobile,
getActiveTab,
getPlatform
getPlatform,
stringToInt
} from 'utils/common';
import {
getEnabledEngines,
Expand Down Expand Up @@ -720,11 +721,9 @@ async function setupNewEngineTab(tabId, tabUrl, token, engine) {
]
});

window.setTimeout(function () {
browser.declarativeNetRequest.updateSessionRules({
removeRuleIds: [tabId]
});
}, 60000);
browser.alarms.create(`delete-net-request-session-rule_${tabId}`, {
delayInMinutes: 1
});
} else {
await showNotification({messageId: 'error_engineSafariOutdated'});
}
Expand Down Expand Up @@ -1355,6 +1354,11 @@ async function onAlarm({name}) {
if (name.startsWith('delete-storage-item')) {
const storageId = name.split('_')[1];
await registry.deleteStorageItem({storageId});
} else if (name.startsWith('delete-net-request-session-rule')) {
const ruleId = stringToInt(name.split('_')[1]);
await browser.declarativeNetRequest.updateSessionRules({
removeRuleIds: [ruleId]
});
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/utils/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,10 @@ async function isValidTab({tab, tabId = null} = {}) {
}
}

function stringToInt(string) {
return parseInt(string, 10);
}

export {
onError,
onComplete,
Expand Down Expand Up @@ -707,5 +711,6 @@ export {
addCssClass,
waitForDocumentLoad,
makeDocumentVisible,
isValidTab
isValidTab,
stringToInt
};

0 comments on commit 941d1ee

Please sign in to comment.