From ae6e024bca7399feda39248246d463f82da95532 Mon Sep 17 00:00:00 2001 From: Ezzudin Alkotob Date: Wed, 3 Sep 2025 14:44:12 -0700 Subject: [PATCH] async fixes --- src/js/background.ts | 2 ++ src/js/background/historyManager.ts | 8 ++------ src/js/content.ts | 2 ++ src/js/globals.ts | 10 ++++++++++ src/js/index.d.ts | 4 +--- src/js/popup/popup.ts | 2 ++ tsconfig.json | 2 +- 7 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 src/js/globals.ts diff --git a/src/js/background.ts b/src/js/background.ts index 3a50741f..b51f221a 100644 --- a/src/js/background.ts +++ b/src/js/background.ts @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +import './globals'; + import {DYNAMIC_STRING_MARKER, Origin, STATES} from './config'; import {MESSAGE_TYPE, ORIGIN_HOST} from './config'; diff --git a/src/js/background/historyManager.ts b/src/js/background/historyManager.ts index 217bd15c..348f6f3a 100644 --- a/src/js/background/historyManager.ts +++ b/src/js/background/historyManager.ts @@ -22,9 +22,7 @@ export async function getRecords(): Promise< [string, {creationTime: number; violations: Array; url: string}] > > { - const tabIDs = await chrome.storage.local.getKeys(); - const entries = await chrome.storage.local.get(tabIDs); - return Object.entries(entries); + return Object.entries(await chrome.storage.local.get(null)); } export async function downloadHashSource( @@ -105,10 +103,8 @@ export async function trackViolationForTab( export async function setUpHistoryCleaner(): Promise { const now = Date.now(); - const keys = await chrome.storage.local.getKeys(); - const entries = await chrome.storage.local.get(keys); - const entriesToDelete = Object.entries(entries) + const entriesToDelete = (await getRecords()) .filter(([_keys, entry]) => now - entry.creationTime >= HISTORY_TTL_MSEC) .map(entry => entry[0]); diff --git a/src/js/content.ts b/src/js/content.ts index 5ee9dff5..4cc7a406 100644 --- a/src/js/content.ts +++ b/src/js/content.ts @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +import './globals'; + import { MESSAGE_TYPE, DOWNLOAD_SRC_ENABLED, diff --git a/src/js/globals.ts b/src/js/globals.ts new file mode 100644 index 00000000..3f470088 --- /dev/null +++ b/src/js/globals.ts @@ -0,0 +1,10 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// See https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Chrome_incompatibilities +// To enable Promise APIs we need to use `browser` outside of Chrome +self.chrome = self.browser ?? self.chrome; diff --git a/src/js/index.d.ts b/src/js/index.d.ts index 2f42ac45..443bcbf9 100644 --- a/src/js/index.d.ts +++ b/src/js/index.d.ts @@ -22,8 +22,6 @@ declare global { showSaveFilePicker: (_: { suggestedName: string; }) => Promise; - } - interface FileSystemFileHandle { - createWritable: () => Promise; + browser: typeof chrome; } } diff --git a/src/js/popup/popup.ts b/src/js/popup/popup.ts index 0d86c656..9cdc2759 100644 --- a/src/js/popup/popup.ts +++ b/src/js/popup/popup.ts @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +import '../globals'; + import type {Origin, State} from '../config'; import { DOWNLOAD_SRC_ENABLED, diff --git a/tsconfig.json b/tsconfig.json index 93e95a7f..ffb817ce 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,6 +5,6 @@ "moduleResolution": "node", "noFallthroughCasesInSwitch": true, "strict": true, - "target": "ES6" + "target": "ES2017" } }