{"record":{"id":"46cb32feffb895dd","repo":"jackwener/OpenCLI","slug":"actionlabel-failed-invalid-browser-response","errorCode":null,"errorMessage":"${actionLabel} failed: invalid browser response","messagePattern":"(.+?) failed: invalid browser response","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/hupu/utils.js","lineNumber":306,"sourceCode":"      } catch (error) {\n        return {\n          ok: false,\n          error: error instanceof Error ? error.message : String(error)\n        };\n      }\n    })()\n  `;\n}\n/**\n * Execute authenticated Hupu JSON requests inside the browser page so\n * cookies and the thread referer come from the live logged-in session.\n */\nexport async function postHupuJson(page, tid, apiUrl, body, actionLabel, mode = 'default') {\n    const referer = getHupuThreadUrl(tid);\n    await page.goto(referer);\n    const result = await page.evaluate(buildBrowserJsonPostScript(apiUrl, body, mode));\n    if (!result || typeof result !== 'object') {\n        throw new CommandExecutionError(`${actionLabel} failed: invalid browser response`);\n    }\n    if (result.status === 401 || result.status === 403) {\n        throw new AuthRequiredError('bbs.hupu.com', `${actionLabel} failed: please log in to Hupu first`);\n    }\n    if (result.error) {\n        throw new CommandExecutionError(`${actionLabel} failed: ${result.error}`);\n    }\n    if (!result.ok) {\n        const detail = result.data?.msg || result.data?.message || `HTTP ${result.status ?? 'unknown'}`;\n        throw new CommandExecutionError(`${actionLabel} failed: ${detail}`);\n    }\n    return result.data ?? {};\n}\n","sourceCodeStart":288,"sourceCodeEnd":320,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/hupu/utils.js#L288-L320","documentation":"postHupuJson runs a fetch POST inside the browser page and expects page.evaluate to return an object of shape {ok, status, data} (or {ok:false, error}). When the evaluate result is null/undefined or not an object — meaning the in-page script did not return its structured result — it throws CommandExecutionError '<action> failed: invalid browser response'. This guards against browser automation failures rather than API-level errors.","triggerScenarios":"Calling postHupuJson (like/unlike/reply commands) when page.evaluate returns nothing: the in-page async script was interrupted, the page navigated/closed mid-evaluate, the browser context was destroyed, or evaluate deserialization failed.","commonSituations":"The automated browser tab crashed or was closed during the POST, the page navigated away (redirect) while evaluate was pending, a Playwright/Puppeteer issue evaluating async script strings, or a network disconnect killing the in-page fetch so the script never resolved.","solutions":["Re-run the command — a transient tab crash or navigation race often resolves on retry.","Ensure the browser session stays open and no navigation happens while the command runs.","Confirm the thread URL (tid) loads correctly first; a failing page.goto can leave the page in a bad state.","Upgrade/verify the browser automation driver if evaluate consistently returns undefined.","Check network connectivity to bbs.hupu.com; a fetch failure should normally return {ok:false,error}, so a bare non-object implies the script never completed."],"exampleFix":"// before\nconst result = await page.evaluate(buildBrowserJsonPostScript(apiUrl, body, mode));\n// after — validate the page is ready before evaluating\nawait page.goto(referer, { waitUntil: 'domcontentloaded' });\nconst result = await page.evaluate(buildBrowserJsonPostScript(apiUrl, body, mode));\nif (!result || typeof result !== 'object') throw new CommandExecutionError(`${actionLabel} failed: invalid browser response`);","handlingStrategy":"type-guard","validationCode":"// validate prerequisites before the in-page POST\nif (page.isClosed?.()) throw new Error('browser page already closed');\nawait page.goto(getHupuThreadUrl(tid), { waitUntil: 'domcontentloaded' });\nif (!/^\\d+$/.test(String(tid))) throw new Error(`invalid tid: ${tid}`);","typeGuard":"function isBrowserPostResult(r) {\n  return typeof r === 'object' && r !== null &&\n    (typeof r.ok === 'boolean') &&\n    ('status' in r || 'error' in r);\n}\n// usage\nconst result = await page.evaluate(script);\nif (!isBrowserPostResult(result)) throw new CommandExecutionError('invalid browser response');","tryCatchPattern":"try {\n  await postHupuJson(page, tid, apiUrl, body, 'Like reply');\n} catch (err) {\n  if (/invalid browser response/.test(err.message)) {\n    await sleep(1000);\n    return retryOnce(); // transient evaluate/navigation failure\n  }\n  throw err;\n}","preventionTips":["Never navigate or close the tab while a write command is in flight.","Wait for page load (domcontentloaded) before the command executes.","Retry once — this error is usually a transient evaluate/navigation race.","Keep the automation driver (Playwright/Puppeteer) up to date; stale drivers can break async evaluate string scripts.","Check network stability to bbs.hupu.com before batch operations."],"tags":["hupu","browser-automation","http-api"],"backgroundTag":"invalid-browser-evaluate-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}