{"record":{"id":"671bd8366cd399dd","repo":"koala73/worldmonitor","slug":"notifications-permission-was-not-granted","errorCode":null,"errorMessage":"Notifications permission was not granted.","messagePattern":"Notifications permission was not granted\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/services/push-notifications.ts","lineNumber":141,"sourceCode":" * Ask permission (if needed), subscribe via pushManager, and register\n * the endpoint with the server. Resolves with the payload the server\n * accepted, or throws on cancel / denial / network failure.\n */\nexport async function subscribeToPush(expectedUserId?: string): Promise<SubscriptionPayload> {\n  assertExpectedAccount(expectedUserId);\n  if (!isWebPushSupported()) {\n    throw new Error('Web push is not supported in this browser.');\n  }\n  const reg = await getRegistration();\n  if (!reg) throw new Error('Service worker unavailable.');\n\n  const perm = await Notification.requestPermission();\n  if (perm !== 'granted') {\n    throw new Error(\n      perm === 'denied'\n        ? 'Notifications are blocked. Enable them in your browser settings to continue.'\n        : 'Notifications permission was not granted.',\n    );\n  }\n\n  // Re-use an existing subscription if pushManager already has one\n  // for this origin. Re-registering via POST keeps server state in\n  // sync even when the browser has a stale subscription — this is\n  // important after sign-out/sign-in, where the browser's push\n  // identity persists but the Convex row does not.\n  let sub = await reg.pushManager.getSubscription();\n  if (!sub) {\n    sub = await reg.pushManager.subscribe({\n      userVisibleOnly: true,\n      applicationServerKey: urlBase64ToUint8Array(VAPID_PUBLIC_KEY) as BufferSource,\n    });\n  }\n\n  const payload = subscriptionToPayload(sub);\n  if (!payload) {\n    // Chrome occasionally hands back a subscription with null keys on","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/koala73/worldmonitor/blob/eeab0a219fce0f02a00603b532dbae9041b934ac/src/services/push-notifications.ts#L123-L159","documentation":"UI error in subscribeToPush: Notification.requestPermission() completed without 'granted' — the user denied or dismissed the browser permission prompt. The subscription flow deliberately stops because a push subscription is unusable without permission.","triggerScenarios":"Thrown at src/services/push-notifications.ts:141 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Re-enable notifications in the browser's site settings and retry","Follow the browser's flow to undo a denial (usually via the permissions icon in the address bar)"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"eeab0a219fce0f02a00603b532dbae9041b934ac","analyzedAt":"2026-08-21T16:51:25.751Z","contentChangedAt":"2026-08-21T16:51:25.751Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}