1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-21 11:35:34 +01:00

Add lint to try to limit reappearance of Safari memory leaks (#6382)

This commit is contained in:
Daniel García 2023-10-10 19:13:50 +02:00 committed by GitHub
parent 3e720c05f2
commit 524123ac01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -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']"
}
]
}
}
]
}

View File

@ -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<typeof chrome.storage.onChanged.addListener>[0]
) {
// eslint-disable-next-line no-restricted-syntax
chrome.storage.onChanged.addListener(callback);
if (BrowserApi.isSafariApi && !BrowserApi.isBackgroundPage(window)) {