diff --git a/src/adapters/web-push/service-worker-runtime.ts b/src/adapters/web-push/service-worker-runtime.ts index 4182c241..a339a0ac 100644 --- a/src/adapters/web-push/service-worker-runtime.ts +++ b/src/adapters/web-push/service-worker-runtime.ts @@ -273,7 +273,9 @@ function notificationClickEventFacade( typeof value.waitUntil !== "function" || !isRecord(value.notification) || typeof value.notification.close !== "function" || - !Object.hasOwn(value.notification, "data") + // 06-01. `data` is a WebIDL getter on `Notification.prototype`, never an + // own property, so the check must follow the prototype chain. + !("data" in value.notification) ) { return null; } diff --git a/tests/unit/web-push-worker-runtime.test.ts b/tests/unit/web-push-worker-runtime.test.ts index ff9c8f58..44672418 100644 --- a/tests/unit/web-push-worker-runtime.test.ts +++ b/tests/unit/web-push-worker-runtime.test.ts @@ -106,6 +106,25 @@ function manualScheduler(): Readonly<{ }; } +/** + * 06-01. WebIDL shape of a real `Notification`: `data` is a getter and + * `close` a method on the prototype, so the instance has no own keys + * (checked in Chromium, Firefox and WebKit). + */ +class WebIdlNotification { + readonly #data: unknown; + closed = 0; + constructor(data: unknown) { + this.#data = data; + } + get data(): unknown { + return this.#data; + } + close(): void { + this.closed += 1; + } +} + describe("Web Push worker runtime", () => { it("waits for strict hint handling and shows only registry-owned safe copy", async () => { const store = await activeFence(); @@ -703,13 +722,18 @@ describe("Web Push worker runtime", () => { "pushsubscriptionchange", ]); let clickWait: Promise | null = null; + const notification = new WebIdlNotification(clickData()); + expect(Object.keys(notification)).toEqual(["closed"]); + expect(Object.hasOwn(notification, "data")).toBe(false); listeners.get("notificationclick")?.({ - notification: { data: clickData(), close() {} }, + notification, waitUntil(task: Promise) { clickWait = task; }, }); + expect(clickWait).not.toBeNull(); await clickWait; + expect(notification.closed).toBe(1); let subscriptionWait: Promise | null = null; listeners.get("pushsubscriptionchange")?.({ waitUntil(task: Promise) {