Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions extension/js/common/browser/browser-msg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,20 @@ export class BrowserMsg {
BrowserMsg.HANDLERS_REGISTERED_BACKGROUND[name] = handler;
}

public static async guardAlarmFlood() {
const MAX_ALARMS = 500; // Chrome’s hard cap
const CLEAR_THRESHOLD = 100; // when to reset down before hitting limits

// 2) Check current alarms
const existing = await chrome.alarms.getAll();

// 3) If we’re within CLEAR_THRESHOLD of the cap, wipe them out
if (existing.length >= MAX_ALARMS - CLEAR_THRESHOLD) {
console.warn(`Alarms at ${existing.length}; recycling…`);
await chrome.alarms.clearAll();
}
}

public static async createIntervalAlarm(action: string, periodInMinutes: number) {
const alarmName = `${action}_interval`;

Expand Down
4 changes: 3 additions & 1 deletion extension/js/common/core/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,9 @@ export class Url {
* todo - the camelCase or snake_case functionality can now be removed
*/
public static parse = (expectedKeys: string[], parseThisUrl?: string) => {
const url = parseThisUrl || window.location.search.replace('?', '');
const replacedLocation = typeof window !== 'undefined' ? window.location.search.replace('?', '') : 'https://service-worker.context'; // Placeholder URL when running in a service‐worker context

const url = parseThisUrl ?? replacedLocation;

const valuePairs = url.split('?').pop()?.split('&') ?? []; // str.split('?') string[].length will always be >= 1
const rawParams = new Map<string, string>();
Expand Down
1 change: 1 addition & 0 deletions extension/js/service_worker/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ console.info('background.js service worker starting');
let db: IDBDatabase;
let storage: GlobalStoreDict;
const inMemoryStore = new ExpirationCache<string>('in_memory_store', 4 * 60 * 60 * 1000); // 4 hours
await BrowserMsg.guardAlarmFlood();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about just doing await chrome.alarms.clearAll() here? (without checking for alarms count in separate function)
I think reported case happens only for users who previously had more than 500 alarms when we were using random values in alarm names. this way we'll just remove all these unneeded alarms, and similar errors won't appear in the future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed—this is simpler, as there are no saved critical alarms impacting current functionality.

await BrowserMsg.createIntervalAlarm('delete_expired', 1); // each minute

try {
Expand Down
Loading