{"record":{"id":"98742af75e1d95ca","repo":"benweet/stackedit","slug":"the-authorize-window-was-blocked","errorCode":null,"errorMessage":"The authorize window was blocked.","messagePattern":"The authorize window was blocked\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/services/networkSvc.js","lineNumber":168,"sourceCode":"      const state = utils.uid();\n      const authorizeUrl = utils.addQueryParams(url, {\n        ...params,\n        state,\n        redirect_uri: constants.oauth2RedirectUri,\n      });\n\n      let iframeElt;\n      let wnd;\n      if (silent) {\n        // Use an iframe as wnd for silent mode\n        iframeElt = utils.createHiddenIframe(authorizeUrl);\n        document.body.appendChild(iframeElt);\n        wnd = iframeElt.contentWindow;\n      } else {\n        // Open a tab otherwise\n        wnd = window.open(authorizeUrl);\n        if (!wnd) {\n          throw new Error('The authorize window was blocked.');\n        }\n      }\n\n      let checkClosedInterval;\n      let closeTimeout;\n      let msgHandler;\n      try {\n        return await new Promise((resolve, reject) => {\n          if (silent) {\n            iframeElt.onerror = () => {\n              reject(new Error('Unknown error.'));\n            };\n            closeTimeout = setTimeout(() => {\n              if (!reattempt) {\n                reject(new Error('REATTEMPT'));\n              } else {\n                isConnectionDown = true;\n                store.commit('setOffline', true);","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/benweet/stackedit/blob/6dce2a5e36b755a0c244522b48a06c91a2df0f59/src/services/networkSvc.js#L150-L186","documentation":"startOauth2 opens the provider's authorize URL in a popup tab (or iframe when configured). If window.open() returns null the popup was blocked, so the OAuth flow cannot continue and the error is thrown at src/services/networkSvc.js:168. Browsers block window.open calls that are not the direct result of a user gesture, and they also block any popup after an async await delay.","triggerScenarios":"Calling startOauth2 after an await or timer such that window.open(authorizeUrl) runs outside a user-gesture context; popup blocker blocking the tab; iframe path not taken and window.open returns null.","commonSituations":"Users click 'Authorize', the token request await resolves too slowly, then the popup opens and is blocked; browser popup blocker set to strict; kiosk/embedded browsers with popups disabled.","solutions":["Trigger startOauth2 synchronously from the click handler, or open a blank window before the await and set its location to authorizeUrl afterwards.","Whitelist the site in the browser's popup blocker settings and retry.","Retry the authorization action with a direct user click.","Fall back to a full-page redirect to the authorize URL instead of a popup."],"exampleFix":"// before\nconst accessToken = await someAsyncPreStep();\nwnd = window.open(authorizeUrl);\n// after\nconst wnd = window.open('', '_blank'); // inside the click handler, keeps user gesture\nconst accessToken = await someAsyncPreStep();\nwnd.location.href = authorizeUrl;","handlingStrategy":"try-catch","validationCode":"function popupsLikelyAllowed() {\n  const test = window.open('', '_blank');\n  if (test) { test.close(); return true; }\n  return false;\n}","typeGuard":"function openedWindow(wnd) {\n  return wnd !== null && typeof wnd === 'object' && !wnd.closed;\n}","tryCatchPattern":"try {\n  await networkSvc.startOauth2(...);\n} catch (err) {\n  if (/blocked/i.test(err.message)) {\n    showRetryBanner('Popup blocked — allow popups for this site and click Authorize again.');\n  }\n}","preventionTips":["Call window.open synchronously inside the click handler before any await.","Whitelist the app origin in popup blockers for corporate browsers.","Provide a full-page redirect fallback when window.open returns null.","Detect popup blocking proactively with a probe window."],"tags":["oauth","popup-blocked","browser"],"backgroundTag":"popup-blocked","analyzedSha":"6dce2a5e36b755a0c244522b48a06c91a2df0f59","analyzedAt":"2026-09-01T00:49:23.866Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}