{"record":{"id":"6204c7f8f83eee7d","repo":"jackwener/OpenCLI","slug":"coupang-add-to-cart-evaluation-failed-error-me","errorCode":null,"errorMessage":"coupang add-to-cart evaluation failed: ${error?.message || error}","messagePattern":"coupang add-to-cart evaluation failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/coupang/add-to-cart.js","lineNumber":122,"sourceCode":"        { name: 'product-id', positional: true, required: false, help: 'Coupang product ID' },\n        { name: 'url', required: false, help: 'Canonical product URL' },\n    ],\n    columns: ['ok', 'product_id', 'url', 'message'],\n    func: async (page, kwargs) => {\n        const rawProductId = kwargs['product-id'];\n        if (!rawProductId && !kwargs.url) {\n            throw new ArgumentError('Either --product-id or --url is required');\n        }\n        const productId = rawProductId\n            ? requireProductIdArg(rawProductId, 'product-id')\n            : requireProductIdArg(kwargs.url, '--url');\n        const targetUrl = canonicalizeProductUrl(kwargs.url, productId);\n        const finalUrl = targetUrl || canonicalizeProductUrl('', productId);\n        await page.goto(finalUrl).catch((error) => {\n            throw new CommandExecutionError(`coupang add-to-cart navigation failed: ${error?.message || error}`);\n        });\n        const result = await page.evaluate(buildAddToCartEvaluate(productId)).catch((error) => {\n            throw new CommandExecutionError(`coupang add-to-cart evaluation failed: ${error?.message || error}`);\n        });\n        const loginHints = result?.loginHints ?? {};\n        if (loginHints.hasLoginLink && !loginHints.hasMyCoupang) {\n            throw new AuthRequiredError('coupang.com', 'Please log into Coupang in Chrome and retry.');\n        }\n        const actualProductId = normalizeProductId(result?.currentProductId || productId);\n        if (result?.reason === 'PRODUCT_MISMATCH') {\n            const observed = actualProductId ? `got ${actualProductId}` : 'no product id observed';\n            throw new CommandExecutionError(`Product mismatch: expected ${productId}, ${observed}`);\n        }\n        if (result?.reason === 'OPTION_REQUIRED') {\n            throw new CommandExecutionError('This product requires option selection and is not supported in v1.');\n        }\n        if (result?.reason === 'ADD_TO_CART_BUTTON_NOT_FOUND') {\n            throw new CommandExecutionError('Could not find an add-to-cart button on the product page.');\n        }\n        if (!result?.ok) {\n            throw new CommandExecutionError('Failed to confirm add-to-cart success.');","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/coupang/add-to-cart.js#L104-L140","documentation":"This CommandExecutionError wraps a failure of page.evaluate(buildAddToCartEvaluate(productId)) — i.e. the in-page script that performs add-to-cart threw or could not be evaluated. Common causes inside evaluate: the page DOM isn't what the script expects (selectors missing), the page navigated away mid-evaluation, or an exception raised inside the evaluated function. The library catches it and rethrows with the underlying message.","triggerScenarios":"`page.evaluate(...)` rejects after a successful goto: Execution context destroyed by a client-side redirect on the product page, an uncaught exception in buildAddToCartEvaluate's DOM logic (e.g. add-to-cart button/app state missing), or the page being navigated/closed during evaluation.","commonSituations":"Coupang changing their product-page DOM so the injected script's selectors throw, the product page auto-redirecting (sold out, region block) destroying the execution context, slow page load where the script runs before the app hydrates, or an out-of-stock item whose UI path errors.","solutions":["Check the wrapped message: 'Execution context was destroyed' means a redirect — add a wait/retry or block navigations during evaluate","Update the library version if Coupang changed their page DOM; the evaluate script may need new selectors","Load the product page manually and verify it's a normal, in-stock product page (not redirecting to sold-out/region error)","Retry the command once — transient hydration timing often causes one-off evaluate failures"],"exampleFix":"// before\nawait page.goto(finalUrl);\nconst result = await page.evaluate(buildAddToCartEvaluate(productId)); // context destroyed by redirect\n// after\nawait page.goto(finalUrl, { waitUntil: 'networkidle' });\nawait page.waitForSelector('.prod-atf, #addToCart', { timeout: 15000 });\nconst result = await page.evaluate(buildAddToCartEvaluate(productId));","handlingStrategy":"try-catch","validationCode":"await page.goto(productUrl, { waitUntil: 'networkidle' });\nconst ready = await page.waitForSelector('.prod-atf, [data-testid=\"add-to-cart\"]', { timeout: 15000 }).catch(() => null);\nif (!ready) throw new Error('product page DOM not ready — do not run add-to-cart evaluate yet');","typeGuard":"function isEvaluateFailure(e) {\n  return /add-to-cart evaluation failed|Execution context was destroyed/i.test(e?.message || '');\n}","tryCatchPattern":"try {\n  await runCli('coupang add-to-cart', '--product-id', productId);\n} catch (e) {\n  if (/Execution context was destroyed/.test(e.message)) {\n    // page redirected mid-evaluate: reload and retry once\n    return runCli('coupang add-to-cart', '--product-id', productId);\n  }\n  if (/evaluation failed/.test(e.message)) {\n    console.error('DOM may have changed; update the library or inspect the product page');\n  }\n  throw e;\n}","preventionTips":["Wait for page hydration/networkidle before running the command on slow connections","Distinguish 'context destroyed' (redirect — retry) from selector errors (DOM change — update library)","Verify the product is in stock and doesn't redirect (sold-out/region pages)","Keep the library updated as Coupang evolves its product-page DOM"],"tags":["page-evaluate","playwright","coupang","browser-automation","dom"],"backgroundTag":"page-evaluation-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}