diff --git a/.eslintrc.json b/.eslintrc.json index d6c329a94d..44b4e09adf 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -179,6 +179,23 @@ "rules": { "no-restricted-imports": ["error", { "patterns": ["@bitwarden/vault/*", "src/**/*"] }] } + }, + { + "files": ["apps/browser/src/**/*.ts", "libs/**/*.ts"], + "excludedFiles": "apps/browser/src/autofill/{content,notification}/**/*.ts", + "rules": { + "no-restricted-syntax": [ + "error", + { + "message": "Using addListener in the browser popup produces a memory leak in Safari, use `BrowserApi.messageListener` instead", + "selector": "CallExpression > [object.object.object.name='chrome'][object.object.property.name='runtime'][object.property.name='onMessage'][property.name='addListener']" + }, + { + "message": "Using addListener in the browser popup produces a memory leak in Safari, use `BrowserApi.storageChangeListener` instead", + "selector": "CallExpression > [object.object.object.name='chrome'][object.object.property.name='storage'][object.property.name='onChanged'][property.name='addListener']" + } + ] + } } ] } diff --git a/apps/browser/src/platform/browser/browser-api.ts b/apps/browser/src/platform/browser/browser-api.ts index b71b8b80b6..5d0c2f1a51 100644 --- a/apps/browser/src/platform/browser/browser-api.ts +++ b/apps/browser/src/platform/browser/browser-api.ts @@ -208,6 +208,7 @@ export class BrowserApi { name: string, callback: (message: any, sender: chrome.runtime.MessageSender, response: any) => void ) { + // eslint-disable-next-line no-restricted-syntax chrome.runtime.onMessage.addListener(callback); if (BrowserApi.isSafariApi && !BrowserApi.isBackgroundPage(window)) { @@ -219,6 +220,7 @@ export class BrowserApi { static storageChangeListener( callback: Parameters[0] ) { + // eslint-disable-next-line no-restricted-syntax chrome.storage.onChanged.addListener(callback); if (BrowserApi.isSafariApi && !BrowserApi.isBackgroundPage(window)) {