{"record":{"id":"c091009d50e4d6b2","repo":"jackwener/OpenCLI","slug":"unexpected-amazon-probe-json-stringify-probe","errorCode":null,"errorMessage":"Unexpected Amazon probe: ${JSON.stringify(probe)}","messagePattern":"Unexpected Amazon probe: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/amazon/auth.js","lineNumber":36,"sourceCode":"      const navLink = document.querySelector('#nav-link-accountList');\n      if (!navLink) {\n        return { kind: 'auth', detail: 'Amazon header missing nav-link-accountList — layout changed or robot challenge' };\n      }\n      const greeting = (navLink.querySelector('.nav-line-1, #nav-link-accountList-nav-line-1') || {}).textContent || '';\n      const trimmed = greeting.trim();\n      if (/sign\\\\s*in/i.test(trimmed)) {\n        return { kind: 'auth', detail: 'Amazon header shows \"Hello, sign in\" — anonymous' };\n      }\n      const m = trimmed.match(/^Hello,?\\\\s+(.+)$/i);\n      const name = m ? m[1].trim() : '';\n      if (!name) {\n        return { kind: 'auth', detail: 'Amazon greeting unparseable: ' + trimmed };\n      }\n      return { ok: true, user_name: name };\n    })()\n  `);\n  if (probe?.kind === 'auth') throw new AuthRequiredError('amazon.com', probe.detail);\n  if (!probe?.ok) throw new CommandExecutionError(`Unexpected Amazon probe: ${JSON.stringify(probe)}`);\n  return { user_name: probe.user_name };\n}\n\nregisterSiteAuthCommands({\n  site: 'amazon',\n  domain: 'amazon.com',\n  loginUrl: 'https://www.amazon.com/ap/signin?openid.return_to=https%3A%2F%2Fwww.amazon.com%2F&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.assoc_handle=usflex&openid.mode=checkid_setup&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0',\n  columns: ['user_name'],\n  quickCheck: hasAmazonSessionCookies,\n  verify: verifyAmazonIdentity,\n  poll: async (page) => {\n    if (!await hasAmazonSessionCookies(page)) {\n      throw new AuthRequiredError('amazon.com', 'Waiting for Amazon at-main / x-main cookie');\n    }\n    return verifyAmazonIdentity(page);\n  },\n});\n","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/amazon/auth.js#L18-L54","documentation":"CommandExecutionError thrown when the in-page identity probe returns neither {kind:'auth'} nor {ok:true} — e.g. null, undefined, or an object with unexpected shape. This is a defensive branch for probe results outside the two expected outcomes, usually indicating the evaluate() script failed to run or returned something unparsable rather than a clean auth verdict.","triggerScenarios":"verifyAmazonIdentity calls page.evaluate with the probe IIFE and gets back null/undefined (page navigation destroyed the execution context, evaluate string unsupported) or a value lacking both kind:'auth' and ok:true — then `JSON.stringify(probe)` is embedded in the thrown message.","commonSituations":"Homepage redirected mid-evaluate (robot check, captcha interstitial) so the script context is destroyed; browser page crashed or closed; Amazon served a page where the script threw before returning; puppeteer-style evaluate returning undefined because the page blocked script execution.","solutions":["Retry after opening amazon.com manually and dismissing any captcha/robot interstitial","Ensure the shared Chrome page stays open and is not navigated/closed during the verify run","Read the JSON in the message to see exactly what the probe returned and reproduce that page state manually","If it reproduces on a normal homepage, file a bug with the embedded probe payload — the probe script likely needs to handle a new Amazon layout"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"for (let i = 0; i < 3; i++) {\n  try {\n    return await opencli.call('amazon auth verify');\n  } catch (e) {\n    if (/Unexpected Amazon probe/.test(e.message)) { await sleep(2000); continue; }\n    throw e;\n  }\n}\nthrow new Error('amazon verify kept returning unexpected probe results');","preventionTips":["Keep the browser page open and idle during verify; avoid concurrent navigation","Dismiss captcha/robot interstitials before running auth commands","Parse the embedded probe JSON in the message to diagnose recurring shapes"],"tags":["amazon","dom-scraping","browser-automation","unexpected-state"],"backgroundTag":"unexpected-scrape-probe-result","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}