{"record":{"id":"f3a357d2157716e4","repo":"RocketChat/Rocket.Chat","slug":"could-not-open-popup","errorCode":null,"errorMessage":"Could not open popup","messagePattern":"Could not open popup","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/client/lib/openCASLoginPopup.ts","lineNumber":20,"sourceCode":"import { getRootUrlPathPrefix } from './meteorRuntimeConfig';\nimport { settings } from './settings';\n\nconst openCenteredPopup = (url: string, width: number, height: number) => {\n\tconst screenX = window.screenX ?? window.screenLeft;\n\tconst screenY = window.screenY ?? window.screenTop;\n\tconst outerWidth = window.outerWidth ?? document.body.clientWidth;\n\tconst outerHeight = window.outerHeight ?? document.body.clientHeight - 22;\n\t// XXX what is the 22? Probably the height of the title bar.\n\t// Use `outerWidth - width` and `outerHeight - height` for help in\n\t// positioning the popup centered relative to the current window\n\tconst left = screenX + (outerWidth - width) / 2;\n\tconst top = screenY + (outerHeight - height) / 2;\n\tconst features = `width=${width},height=${height},left=${left},top=${top},scrollbars=yes`;\n\n\tconst newwindow = window.open(url, 'Login', features);\n\n\tif (!newwindow) {\n\t\tthrow new Error('Could not open popup');\n\t}\n\n\tnewwindow.focus();\n\n\treturn newwindow;\n};\n\nconst getPopupUrl = (credentialToken: string): string => {\n\tconst loginUrl = settings.peek<string | undefined>('CAS_login_url');\n\n\tif (!loginUrl) {\n\t\tthrow new Error('CAS_login_url not set');\n\t}\n\n\tconst appUrl = absoluteUrl().replace(/\\/$/, '') + getRootUrlPathPrefix();\n\tconst serviceUrl = `${appUrl}/_cas/${credentialToken}`;\n\tconst url = new URL(loginUrl);\n\turl.searchParams.set('service', serviceUrl);","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/client/lib/openCASLoginPopup.ts#L2-L38","documentation":"Thrown by the CAS login popup helper when window.open() returns null. Browsers return null from window.open when a popup blocker prevents the new window from being created. This function orchestrates the CAS (Central Authentication Service) single sign-on flow by opening a centered popup window for the CAS login URL.","triggerScenarios":"The browser's built-in popup blocker is enabled and blocks the window.open call. A browser extension (ad blocker, privacy extension) blocks popups. window.open is called outside a direct user gesture (some browsers block programmatic popups not triggered by user clicks). Corporate browser policy disables popups.","commonSituations":"User has a popup blocker extension installed. The CAS login is triggered programmatically (e.g., on page load or via a timer) instead of from a click handler. Chrome/Firefox/Safari popup blocker settings are at their default (which blocks non-user-initiated popups). Enterprise managed browsers with strict popup policies.","solutions":["Ensure window.open is called synchronously within a user-initiated event handler (click, tap).","Prompt the user to disable popup blocking for this site if the popup fails to open.","Catch the error and show a fallback message with a direct link the user can click manually.","Use a redirect-based CAS flow instead of a popup if popups are consistently blocked."],"exampleFix":"// before\nconst popup = openCASLoginPopup(token); // may be outside click handler\n// after\n// In a click handler:\nbutton.onclick = () => {\n  try {\n    const popup = openCASLoginPopup(token);\n  } catch {\n    showPopupBlockedMessage();\n  }\n};","handlingStrategy":"try-catch","validationCode":"if (typeof window === 'undefined' || !window.open) {\n  throw new Error('Popups not supported in this environment');\n}\n// ensure called within a user gesture\nconst popup = openCASLoginPopup(token);","typeGuard":"const canOpenPopup = (): boolean =>\n  typeof window !== 'undefined' && typeof window.open === 'function';","tryCatchPattern":"try {\n  const popup = openCASLoginPopup(token);\n} catch (e) {\n  if (e instanceof Error && e.message === 'Could not open popup') {\n    showPopupBlockedGuidance();\n    return;\n  }\n  throw e;\n}","preventionTips":["Always call openCASLoginPopup from within a synchronous user gesture handler (click/tap).","Inform users to allow popups for the Rocket.Chat domain.","Provide a redirect-based fallback when popup blocking is detected.","Test in browsers with default popup blocker settings."],"tags":["cas","authentication","popup","browser","sso","popup-blocker"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}