From 8522cb525697cd2543754e8f9a90bfe226504c72 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Fri, 25 Sep 2026 23:58:19 +0900 Subject: [PATCH] fix(web-push): accept WebIDL notifications whose data is a prototype getter (06-01) Real Notification objects expose `data` as a getter on the prototype, so the own-property check dropped every click. The runtime test now uses a class-based fake with the WebIDL shape. Co-Authored-By: Claude Opus 5.5 --- .../web-push/service-worker-runtime.ts | 4 ++- tests/unit/web-push-worker-runtime.test.ts | 26 ++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) 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) {