Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chrome macOS 15 extra notification workaround #1209

Merged
merged 2 commits into from
Nov 19, 2024
Merged
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
19 changes: 18 additions & 1 deletion src/sw/serviceWorker/ServiceWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -773,10 +773,27 @@ export class ServiceWorker {
badge: notification.badgeIcon,
};

return self.registration.showNotification(
await self.registration.showNotification(
notification.title,
notificationOptions,
);

await this.afterNotificationDisplayMacOS15ChromiumWorkaround();
}

// Workaround: For Chromium browsers displaying an extra notification, even
// when background rules are followed.
// For reference, the notification body is "This site has been updated in the background".
// https://issues.chromium.org/issues/378103918
static async afterNotificationDisplayMacOS15ChromiumWorkaround(): Promise<void> {
const userAgentData = (navigator as any).userAgentData;
const isMacOS = userAgentData?.platform === 'macOS';
const isChromium = !!userAgentData?.brands?.some(
(item: { brand: string }) => item.brand === 'Chromium',
);
if (isMacOS && isChromium) {
await awaitableTimeout(1_000);
}
}

/**
Expand Down
Loading