denoland/deno · error · TypeError

Notification.requestPermission: not supported by this…

Error message

Notification.requestPermission: not supported by this platform/backend

What it means

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).

Solutions

  1. Wrap the call in try/catch and degrade gracefully (fall back to in-app messages or logs)
  2. Run the permission request once at startup inside a safe helper and cache the outcome for the session
  3. Do not assume the three spec states ('granted'/'denied'/'prompt') cover all platforms - treat a throw as 'unsupported'

Example fix

// before
const perm = await Notification.requestPermission();

// after
let perm: string;
try {
  perm = await Notification.requestPermission();
} catch {
  perm = "unsupported"; // this backend has no permission model
}
Defensive patterns

Strategy: try-catch

Try / catch

async function safeRequestPermission(): Promise<PermissionState | "unsupported"> {
  try {
    return await Notification.requestPermission();
  } catch (err) {
    if (err instanceof TypeError && /not supported/.test(err.message)) {
      return "unsupported";
    }
    throw err;
  }
}

Prevention

When it happens

Trigger: `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.

Common situations: Linux desktops without a notification portal backend; headless or containerized environments; early ports of the desktop runtime to a new platform.

Related errors


AI-assisted analysis of denoland/deno@f7822238ca (2026-08-20). Data as JSON: /api/errors/3e6570b7bc6b03df. Report an issue: GitHub.

Appendix: source

Thrown at cli/rt/desktop.rs:577

        get() { return cachedNotificationPermission; },
        enumerable: true,
        configurable: true,
      },
      maxActions: internals.core.propReadOnly(0),
      requestPermission: internals.core.propWritable(function requestPermission(
        cb,
      ) {
        // The Web Notifications spec gates `requestPermission` on a
        // transient user activation. The desktop runtime can't observe
        // renderer activations cleanly (the OS-level UN dialog lives
        // outside Chromium's activation tracking), so we don't enforce.
        const promise = (async () => {
          const s = await op_desktop_request_notification_permission();
          if (s === "unsupported") {
            // Honest signaling: this OS / backend has no notification
            // permission model. Throw rather than silently returning a
            // misleading "denied" or "granted".
            throw new TypeError(
              "Notification.requestPermission: not supported by this platform/backend",
            );
          }
          const perm = laufeyToNotificationPermission(s);
          cachedNotificationPermission = perm;
          return perm;
        })();
        if (typeof cb === "function") {
          // Deprecated callback form. Per spec, the callback is invoked
          // with the resolved permission *and* the promise still resolves.
          promise.then(
            (perm) => { try { cb(perm); } catch (_) {} },
            () => { try { cb("denied"); } catch (_) {} },
          );
        }
        return promise;
      }),
    });

View on GitHub (pinned to f7822238ca)