diff --git a/.changeset/picture-chrome-no-keychain-prompt.md b/.changeset/picture-chrome-no-keychain-prompt.md new file mode 100644 index 0000000000000..497d123d83b34 --- /dev/null +++ b/.changeset/picture-chrome-no-keychain-prompt.md @@ -0,0 +1,7 @@ +--- +'@astryxdesign/cli': patch +--- + +[fix] When `astryx experimental export --pictures` takes its pictures with an installed Google Chrome or Chromium, the browser no longer asks the macOS keychain or the Linux password store for access. Before, each browser start could open a keychain dialog. + +@dante01yoon diff --git a/packages/cli/foundation/render/picture-chrome.mjs b/packages/cli/foundation/render/picture-chrome.mjs index 57a68c68db1b8..b6572e1ee98c7 100644 --- a/packages/cli/foundation/render/picture-chrome.mjs +++ b/packages/cli/foundation/render/picture-chrome.mjs @@ -52,6 +52,11 @@ const browser = spawn( '--no-sandbox', '--hide-scrollbars', '--remote-debugging-pipe', + // The throwaway profile stores no secret. Without these flags, each + // browser start asks the system keychain (macOS) or password store + // (Linux) for access, and the person sees a dialog. + '--use-mock-keychain', + '--password-store=basic', // The browser's own network off: a picture asks the network for nothing. ...QUIET_BROWSER_ARGS, `--user-data-dir=${path.join(os.tmpdir(), 'profile')}`, diff --git a/packages/cli/foundation/render/picture-chrome.test.mjs b/packages/cli/foundation/render/picture-chrome.test.mjs new file mode 100644 index 0000000000000..ec526825f663a --- /dev/null +++ b/packages/cli/foundation/render/picture-chrome.test.mjs @@ -0,0 +1,55 @@ +// Copyright (c) Meta Platforms, Inc. and affiliates. + +import {spawnSync} from 'node:child_process'; +import * as fs from 'node:fs'; +import * as os from 'node:os'; +import * as path from 'node:path'; +import {fileURLToPath} from 'node:url'; +import {afterEach, describe, expect, it} from 'vitest'; + +const SCRIPT = fileURLToPath(new URL('./picture-chrome.mjs', import.meta.url)); + +/** @type {string[]} */ +const dirs = []; +afterEach(() => { + for (const d of dirs.splice(0)) fs.rmSync(d, {recursive: true, force: true}); +}); + +/** + * The flags picture-chrome.mjs starts its browser with, read from a stand-in + * browser that writes them down and stops. + */ +function browserFlags() { + const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-picture-chrome-')); + dirs.push(dir); + const argsFile = path.join(dir, 'args.json'); + const fake = path.join(dir, 'chrome'); + fs.writeFileSync( + fake, + `#!${process.execPath}\n` + + `require('node:fs').writeFileSync(${JSON.stringify(argsFile)}, JSON.stringify(process.argv.slice(2)));\n`, + {mode: 0o755}, + ); + const batch = JSON.stringify([ + { + html: path.join(dir, 'p.html'), + png: path.join(dir, 'p.png'), + mode: 'light', + }, + ]); + spawnSync(process.execPath, [SCRIPT, fake, batch], { + env: {...process.env, TMPDIR: dir}, + timeout: 20_000, + }); + return /** @type {string[]} */ ( + JSON.parse(fs.readFileSync(argsFile, 'utf8')) + ); +} + +describe.skipIf(process.platform === 'win32')("a picture's Chrome", () => { + it('keeps away from the system keychain and password store', () => { + const flags = browserFlags(); + expect(flags).toContain('--use-mock-keychain'); + expect(flags).toContain('--password-store=basic'); + }); +});