{"file":"client/src/open-browser.ts","version":318,"total":54,"from":1,"to":54,"lines":[{"n":1,"text":"// Opening a page in the person's own browser, as `gh auth login` and `wrangler login` do.","atom":"a608","author":"speed","version":60},{"n":2,"text":"// `abso login` opens the approve page with the code already in it, and still prints the","atom":"a608","author":"speed","version":60},{"n":3,"text":"// link and the code: an open that fails, or is skipped, is silent, and the printed link stands.","atom":"a608","author":"speed","version":60},{"n":4,"text":"","atom":"a608","author":"speed","version":60},{"n":5,"text":"import { spawn } from \"node:child_process\";","atom":"a608","author":"speed","version":60},{"n":6,"text":"","atom":"a608","author":"speed","version":60},{"n":7,"text":"/** Why not to open a browser here, or null to open one. */","atom":"a608","author":"speed","version":60},{"n":8,"text":"export function browserSkip(env: Readonly<Record<string, string | undefined>>, platform: string): string | null {","atom":"a608","author":"speed","version":60},{"n":9,"text":"\tif (env.ABSO_NO_BROWSER) return \"ABSO_NO_BROWSER is set\";","atom":"a608","author":"speed","version":60},{"n":10,"text":"\t// Over SSH the browser would open on the far machine's desktop, if it has one.","atom":"a608","author":"speed","version":60},{"n":11,"text":"\tif (env.SSH_CONNECTION || env.SSH_TTY) return \"this is an SSH session\";","atom":"a608","author":"speed","version":60},{"n":12,"text":"\tif (env.CI && env.CI !== \"false\" && env.CI !== \"0\") return \"this is CI\";","atom":"a608","author":"speed","version":60},{"n":13,"text":"\tif (platform !== \"win32\" && platform !== \"darwin\" && !env.DISPLAY && !env.WAYLAND_DISPLAY)","atom":"a608","author":"speed","version":60},{"n":14,"text":"\t\treturn \"there's no display\";","atom":"a608","author":"speed","version":60},{"n":15,"text":"\treturn null;","atom":"a608","author":"speed","version":60},{"n":16,"text":"}","atom":"a608","author":"speed","version":60},{"n":17,"text":"","atom":"a608","author":"speed","version":60},{"n":18,"text":"/**","atom":"a608","author":"speed","version":60},{"n":19,"text":" * The program that opens `url` in the default browser, and its arguments. No shell, so nothing in the url is","atom":"a608","author":"speed","version":60},{"n":20,"text":" * read as shell syntax. On Windows that rules out cmd's start, which cuts a url at its first &.","atom":"a608","author":"speed","version":60},{"n":21,"text":" */","atom":"a608","author":"speed","version":60},{"n":22,"text":"export function openCommand(url: string, platform: string): [string, string[]] {","atom":"a608","author":"speed","version":60},{"n":23,"text":"\tif (platform === \"win32\") return [\"rundll32\", [\"url.dll,FileProtocolHandler\", url]];","atom":"a608","author":"speed","version":60},{"n":24,"text":"\tif (platform === \"darwin\") return [\"open\", [url]];","atom":"a608","author":"speed","version":60},{"n":25,"text":"\treturn [\"xdg-open\", [url]];","atom":"a608","author":"speed","version":60},{"n":26,"text":"}","atom":"a608","author":"speed","version":60},{"n":27,"text":"","atom":"a608","author":"speed","version":60},{"n":28,"text":"/** Only web pages are opened: a link from a server is never handed to the desktop as a file or another program. */","atom":"a608","author":"speed","version":60},{"n":29,"text":"export function isWebLink(url: string): boolean {","atom":"a608","author":"speed","version":60},{"n":30,"text":"\ttry {","atom":"a608","author":"speed","version":60},{"n":31,"text":"\t\tconst u = new URL(url);","atom":"a608","author":"speed","version":60},{"n":32,"text":"\t\treturn u.protocol === \"https:\" || u.protocol === \"http:\";","atom":"a608","author":"speed","version":60},{"n":33,"text":"\t} catch {","atom":"a608","author":"speed","version":60},{"n":34,"text":"\t\treturn false;","atom":"a608","author":"speed","version":60},{"n":35,"text":"\t}","atom":"a608","author":"speed","version":60},{"n":36,"text":"}","atom":"a608","author":"speed","version":60},{"n":37,"text":"","atom":"a608","author":"speed","version":60},{"n":38,"text":"/**","atom":"a608","author":"speed","version":60},{"n":39,"text":" * Opens `url` in the default browser and doesn't wait. Answers whether it started an opener; a failure","atom":"a608","author":"speed","version":60},{"n":40,"text":" * (no such program, refused) is silent.","atom":"a608","author":"speed","version":60},{"n":41,"text":" */","atom":"a608","author":"speed","version":60},{"n":42,"text":"export function openInBrowser(url: string, platform: string = process.platform, run: typeof spawn = spawn): boolean {","atom":"a608","author":"speed","version":60},{"n":43,"text":"\tif (!isWebLink(url)) return false;","atom":"a608","author":"speed","version":60},{"n":44,"text":"\t// The link as the check parsed it, so what opens is exactly what was checked.","atom":"a618","author":"speed","version":62},{"n":45,"text":"\tconst [command, args] = openCommand(new URL(url).href, platform);","atom":"a618","author":"speed","version":62},{"n":46,"text":"\ttry {","atom":"a608","author":"speed","version":60},{"n":47,"text":"\t\tconst child = run(command, args, { detached: true, stdio: \"ignore\", windowsHide: true });","atom":"a608","author":"speed","version":60},{"n":48,"text":"\t\tchild.on(\"error\", () => {});","atom":"a608","author":"speed","version":60},{"n":49,"text":"\t\tchild.unref();","atom":"a608","author":"speed","version":60},{"n":50,"text":"\t\treturn true;","atom":"a608","author":"speed","version":60},{"n":51,"text":"\t} catch {","atom":"a608","author":"speed","version":60},{"n":52,"text":"\t\treturn false;","atom":"a608","author":"speed","version":60},{"n":53,"text":"\t}","atom":"a608","author":"speed","version":60},{"n":54,"text":"}","atom":"a608","author":"speed","version":60}],"atoms":[{"atom":"a608","author":"speed","message":"","time":1791600855389,"timeIso":"2026-10-10T02:54:15.389Z","publish":{"draft":null,"version":60,"agent":"speed","message":"abso login opens the approve page in the browser\n\nLike gh auth login and wrangler login: abso login opens the approve page in the default browser with the code already in it, so nobody copies a link by hand. It still prints the link and the code, which stand when the open fails or is skipped.\n\n- Windows opens with rundll32 url.dll,FileProtocolHandler, macOS with open, Linux with xdg-open. There's no shell, so a link with & in it arrives whole (cmd's start would cut it).\n- No browser with --no-browser or ABSO_NO_BROWSER, over SSH (SSH_CONNECTION or SSH_TTY), under CI, or on Linux and other Unixes with neither DISPLAY nor WAYLAND_DISPLAY.\n- Only http and https links are opened, so a link from a server is never handed to the desktop as a file or a program.\n- The opener starts detached and isn't waited on; a failure is silent.\n\nTests: open-browser.test.ts (each skip, each platform's command, web links only, a failing opener is silent), and two login tests with an injected opener.","time":1791600855763,"timeIso":"2026-10-10T02:54:15.763Z"}},{"atom":"a618","author":"speed","message":"","time":1791601313692,"timeIso":"2026-10-10T03:01:53.692Z","publish":{"draft":null,"version":62,"agent":"speed","message":"Open the link as it was checked\n\nopenInBrowser hands the opener the parsed link (new URL(url).href), the same one the web-link check read, rather than the raw text.","time":1791601313901,"timeIso":"2026-10-10T03:01:53.901Z"}}]}