{"record":{"id":"3e6570b7bc6b03df","repo":"denoland/deno","slug":"notification-requestpermission-not-supported-by-t","errorCode":null,"errorMessage":"Notification.requestPermission: not supported by this platform/backend","messagePattern":"Notification\\.requestPermission: not supported by this platform/backend","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"cli/rt/desktop.rs","lineNumber":577,"sourceCode":"        get() { return cachedNotificationPermission; },\n        enumerable: true,\n        configurable: true,\n      },\n      maxActions: internals.core.propReadOnly(0),\n      requestPermission: internals.core.propWritable(function requestPermission(\n        cb,\n      ) {\n        // The Web Notifications spec gates `requestPermission` on a\n        // transient user activation. The desktop runtime can't observe\n        // renderer activations cleanly (the OS-level UN dialog lives\n        // outside Chromium's activation tracking), so we don't enforce.\n        const promise = (async () => {\n          const s = await op_desktop_request_notification_permission();\n          if (s === \"unsupported\") {\n            // Honest signaling: this OS / backend has no notification\n            // permission model. Throw rather than silently returning a\n            // misleading \"denied\" or \"granted\".\n            throw new TypeError(\n              \"Notification.requestPermission: not supported by this platform/backend\",\n            );\n          }\n          const perm = laufeyToNotificationPermission(s);\n          cachedNotificationPermission = perm;\n          return perm;\n        })();\n        if (typeof cb === \"function\") {\n          // Deprecated callback form. Per spec, the callback is invoked\n          // with the resolved permission *and* the promise still resolves.\n          promise.then(\n            (perm) => { try { cb(perm); } catch (_) {} },\n            () => { try { cb(\"denied\"); } catch (_) {} },\n          );\n        }\n        return promise;\n      }),\n    });","sourceCodeStart":559,"sourceCodeEnd":595,"githubUrl":"https://github.com/denoland/deno/blob/f7822238cab635a3a19f99f493f675fa81a7f9d8/cli/rt/desktop.rs#L559-L595","documentation":"In the desktop runtime, Notification.requestPermission() calls the OS backend via op_desktop_request_notification_permission. When the OS/backend has no notification permission model the op returns \"unsupported\", and the polyfill deliberately throws a TypeError instead of returning a misleading \"granted\" or \"denied\" (honest signaling, per the code comment).","triggerScenarios":"`await Notification.requestPermission()` (or the deprecated callback form, whose returned promise also rejects) on an OS/backend where the desktop runtime's notification permission op reports unsupported.","commonSituations":"Linux desktops without a notification portal backend; headless or containerized environments; early ports of the desktop runtime to a new platform.","solutions":["Wrap the call in try/catch and degrade gracefully (fall back to in-app messages or logs)","Run the permission request once at startup inside a safe helper and cache the outcome for the session","Do not assume the three spec states ('granted'/'denied'/'prompt') cover all platforms - treat a throw as 'unsupported'"],"exampleFix":"// before\nconst perm = await Notification.requestPermission();\n\n// after\nlet perm: string;\ntry {\n  perm = await Notification.requestPermission();\n} catch {\n  perm = \"unsupported\"; // this backend has no permission model\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"async function safeRequestPermission(): Promise<PermissionState | \"unsupported\"> {\n  try {\n    return await Notification.requestPermission();\n  } catch (err) {\n    if (err instanceof TypeError && /not supported/.test(err.message)) {\n      return \"unsupported\";\n    }\n    throw err;\n  }\n}","preventionTips":["Run the permission request once at startup inside a safe helper and cache the result","Treat a rejected requestPermission as 'no notification support', not as 'denied'","Provide a non-notification fallback channel (in-app banner, log) for unsupported platforms"],"tags":["notifications","permissions","desktop","platform-support"],"backgroundTag":"unsupported-platform-feature","analyzedSha":"f7822238cab635a3a19f99f493f675fa81a7f9d8","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}