{"record":{"id":"f7c2459e8a0a7e46","repo":"garrytan/gstack","slug":"keychain-not-found","errorCode":"keychain_not_found","errorMessage":"No encrypted key in Local State for ${browser.name}","messagePattern":"No encrypted key in Local State for (.+?)","errorType":"exception","errorClass":"CookieImportError","httpStatus":null,"severity":"error","filePath":"browse/src/cookie-import-browser.ts","lineNumber":506,"sourceCode":"  const platform = 'win32' as const;\n  const dataDir = getDataDirForPlatform(browser, platform);\n  if (!dataDir) throw new CookieImportError(`No Windows data dir for ${browser.name}`, 'not_installed');\n\n  const localStatePath = path.join(getBaseDir(platform), dataDir, 'Local State');\n  let localState: any;\n  try {\n    localState = JSON.parse(fs.readFileSync(localStatePath, 'utf-8'));\n  } catch (err) {\n    const reason = err instanceof Error ? `: ${err.message}` : '';\n    throw new CookieImportError(\n      `Cannot read Local State for ${browser.name} at ${localStatePath}${reason}`,\n      'keychain_error',\n    );\n  }\n\n  const encryptedKeyB64: string = localState?.os_crypt?.encrypted_key;\n  if (!encryptedKeyB64) {\n    throw new CookieImportError(\n      `No encrypted key in Local State for ${browser.name}`,\n      'keychain_not_found',\n    );\n  }\n\n  // The stored value is base64(b\"DPAPI\" + dpapi_encrypted_bytes) — strip the 5-byte prefix\n  const encryptedKey = Buffer.from(encryptedKeyB64, 'base64').slice(5);\n  const key = await dpapiDecrypt(encryptedKey);\n  keyCache.set(cacheKey, key);\n  return key;\n}\n\nasync function dpapiDecrypt(encryptedBytes: Buffer): Promise<Buffer> {\n  const script = [\n    'Add-Type -AssemblyName System.Security',\n    '$stdin = [Console]::In.ReadToEnd().Trim()',\n    '$bytes = [System.Convert]::FromBase64String($stdin)',\n    '$dec = [System.Security.Cryptography.ProtectedData]::Unprotect($bytes, $null, [System.Security.Cryptography.DataProtectionScope]::CurrentUser)',","sourceCodeStart":488,"sourceCodeEnd":524,"githubUrl":"https://github.com/garrytan/gstack/blob/94993f74012782fd94416dd44b8314f6363a13a4/browse/src/cookie-import-browser.ts#L488-L524","documentation":"Error \"No encrypted key in Local State for ${browser.name}\" thrown in garrytan/gstack.","triggerScenarios":"Thrown at browse/src/cookie-import-browser.ts:506 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"94993f74012782fd94416dd44b8314f6363a13a4","analyzedAt":"2026-08-12T04:06:23.140Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}