denoland/deno · error · TypeError

Failed to execute 'query' on 'Permissions': descriptor…

Error message

Failed to execute 'query' on 'Permissions': descriptor required

What it means

The desktop runtime provides a Permissions implementation whose query() supports the 'notifications' permission. Following the Permissions API, the descriptor must be a non-null object; anything else throws a TypeError with the standard "Failed to execute 'query' on 'Permissions'" prefix.

Solutions

  1. Pass a descriptor object: `await navigator.permissions.query({ name: "notifications" })`
  2. Guard the call: only invoke query when the descriptor is a non-null object with a string name
  3. Remember only the 'notifications' name is meaningful in this runtime

Example fix

// before
const s = await navigator.permissions.query("notifications");

// after
const s = await navigator.permissions.query({ name: "notifications" });
Defensive patterns

Strategy: type-guard

Validate before calling

if (descriptor == null || typeof descriptor !== "object") {
  throw new TypeError("descriptor required");
}

Type guard

function isPermissionDescriptor(d: unknown): d is { name: string } {
  return typeof d === "object" && d !== null &&
    typeof (d as { name?: unknown }).name === "string";
}

Prevention

When it happens

Trigger: `permissions.query()` with no argument; `permissions.query(null)`; passing a bare string `permissions.query("notifications")` instead of the object `{ name: "notifications" }`.

Common situations: Refactoring from a custom permissions helper that accepted strings; copying browser code that queries multiple permissions; forgetting the descriptor wrapper in TypeScript where the type was loosened to any.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at cli/rt/desktop.rs:655

    set onchange(v) { this.#onchange = typeof v === "function" ? v : null; }
  }

  function laufeyToPermissionsApiState(s) {
    // Spec maps "prompt" through verbatim; "unsupported" has no spec
    // analog so we return "denied" — query() shouldn't throw, but we
    // shouldn't lie and say "granted" either.
    switch (s) {
      case "granted": return "granted";
      case "denied": return "denied";
      case "prompt": return "prompt";
      default: return "denied";
    }
  }

  const permissionsImpl = {
    async query(descriptor) {
      if (descriptor == null || typeof descriptor !== "object") {
        throw new TypeError(
          "Failed to execute 'query' on 'Permissions': descriptor required",
        );
      }
      const name = String(descriptor.name);
      if (name === "notifications") {
        // No side effects per spec — never call request_*.
        const s = await op_desktop_query_notification_permission();
        // Keep Notification.permission's cache in sync: a permissions.query
        // result is authoritative and lets the synchronous getter report
        // a current value without us needing a second roundtrip.
        if (s !== "unsupported") {
          cachedNotificationPermission = laufeyToNotificationPermission(s);
        }
        return new PermissionStatus(name, laufeyToPermissionsApiState(s));
      }
      // Unknown / unrouted name. Chrome returns "denied" for descriptors
      // it doesn't recognize; mimic that rather than throwing.
      return new PermissionStatus(name, "denied");

View on GitHub (pinned to f7822238ca)