Skip to content

Commit d13e87d

Browse files
authored
Merge pull request #358 from ezzak/fix_awaits
Fix multiple issues relating to async/await
2 parents 67036bf + ae6e024 commit d13e87d

File tree

7 files changed

+20
-10
lines changed

7 files changed

+20
-10
lines changed

src/js/background.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
import './globals';
9+
810
import {DYNAMIC_STRING_MARKER, Origin, STATES} from './config';
911
import {MESSAGE_TYPE, ORIGIN_HOST} from './config';
1012

src/js/background/historyManager.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ export async function getRecords(): Promise<
2222
[string, {creationTime: number; violations: Array<Violation>; url: string}]
2323
>
2424
> {
25-
const tabIDs = await chrome.storage.local.getKeys();
26-
const entries = await chrome.storage.local.get(tabIDs);
27-
return Object.entries(entries);
25+
return Object.entries(await chrome.storage.local.get(null));
2826
}
2927

3028
export async function downloadHashSource(
@@ -105,10 +103,8 @@ export async function trackViolationForTab(
105103

106104
export async function setUpHistoryCleaner(): Promise<void> {
107105
const now = Date.now();
108-
const keys = await chrome.storage.local.getKeys();
109-
const entries = await chrome.storage.local.get(keys);
110106

111-
const entriesToDelete = Object.entries(entries)
107+
const entriesToDelete = (await getRecords())
112108
.filter(([_keys, entry]) => now - entry.creationTime >= HISTORY_TTL_MSEC)
113109
.map(entry => entry[0]);
114110

src/js/content.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
import './globals';
9+
810
import {
911
MESSAGE_TYPE,
1012
DOWNLOAD_SRC_ENABLED,

src/js/globals.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
// See https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Chrome_incompatibilities
9+
// To enable Promise APIs we need to use `browser` outside of Chrome
10+
self.chrome = self.browser ?? self.chrome;

src/js/index.d.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ declare global {
2222
showSaveFilePicker: (_: {
2323
suggestedName: string;
2424
}) => Promise<FileSystemFileHandle>;
25-
}
26-
interface FileSystemFileHandle {
27-
createWritable: () => Promise<WritableStream>;
25+
browser: typeof chrome;
2826
}
2927
}

src/js/popup/popup.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
import '../globals';
9+
810
import type {Origin, State} from '../config';
911
import {
1012
DOWNLOAD_SRC_ENABLED,

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"moduleResolution": "node",
66
"noFallthroughCasesInSwitch": true,
77
"strict": true,
8-
"target": "ES6"
8+
"target": "ES2017"
99
}
1010
}

0 commit comments

Comments
 (0)