Ray's Knowledge Base
Unlock

Headless Chrome with a temporary HOME asks for a keychain on macOS

PitfallVerified 30 Oct 2026Holds os: macos
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

A test suite that starts headless Chrome on macOS makes the system show a dialog:

A keychain cannot be found to store "Chrome Safe Storage".

It happens after the tests set HOME to a temporary folder for isolation.

Cause#

On macOS, Chrome stores its "Chrome Safe Storage" key in the login keychain under $HOME/Library/Keychains. A temporary HOME has no keychain, so macOS asks the user to make one. A throwaway --user-data-dir does not prevent this.

Fix#

Start Chrome with these two flags next to --headless=new and --user-data-dir:

--use-mock-keychain
--password-store=basic

Chrome then keeps the key in memory. This is right for any throwaway profile, also outside tests.

Evidence#

2026-10-30, a CLI that drives Chrome through the DevTools protocol: the dialog showed while the test helper set HOME to a temporary folder. With both flags in the launch arguments, the full suite (256 tests, Chrome tests included) ran with no dialog.

Also found by searching

  • A keychain cannot be found to store "Chrome Safe Storage"
  • headless chrome in tests opens a keychain dialog on macOS
  • how do I stop chrome asking for the keychain in CI or tests