jackwener/OpenCLI · error · CommandExecutionError
Failed to open Zhihu answer ${target.answerId}: ${error inst
Error message
Failed to open Zhihu answer ${target.answerId}: ${error instanceof Error ? error.message : String(error)} What it means
extractAnswer first navigates the Browser Bridge page to https://www.zhihu.com/answer/<answerId>. If page.goto rejects — unreachable host, DNS failure, timeout, connection reset, or the bridge cannot control the tab — the error is converted to a CommandExecutionError that names the answer id and includes a remediation hint: open the URL in Chrome and retry once reachable. It fires before any scraping or API call happens.
Source
Thrown at clis/zhihu/download-helpers.js:150
return {
title: document.querySelector('.Post-Title, h1.ContentItem-title, .ArticleTitle')?.textContent?.trim() || 'untitled',
author: document.querySelector('.AuthorInfo-name, .UserLink-link')?.textContent?.trim() || '',
publishTime: document.querySelector('.ContentItem-time, .Post-Time')?.textContent?.trim() || '',
...normalized
};
})()
`).catch((error) => {
throw new CommandExecutionError(`Zhihu column extraction failed: ${error instanceof Error ? error.message : String(error)}`);
});
return requireArticle(raw);
}
export async function extractAnswer(page, target) {
try {
await page.goto(`https://www.zhihu.com/answer/${target.answerId}`);
}
catch (error) {
throw new CommandExecutionError(
`Failed to open Zhihu answer ${target.answerId}: ${error instanceof Error ? error.message : String(error)}`,
'Open the answer URL in Chrome and retry after the page is reachable.',
);
}
const currentUrl = typeof page.getCurrentUrl === 'function' ? await page.getCurrentUrl().catch(() => '') : '';
const currentTarget = parseAnswerTarget(currentUrl);
if (!currentTarget || currentTarget.answerId !== target.answerId || !currentTarget.questionId
|| (target.questionId && currentTarget.questionId && target.questionId !== currentTarget.questionId)) {
throw new CommandExecutionError(`Zhihu answer navigation changed identity for answer ${target.answerId}`);
}
const apiUrl = `https://www.zhihu.com/api/v4/answers/${target.answerId}?include=content,author,created_time,question,url`;
const normalize = `(${normalizeContentImages.toString()})`;
const raw = await page.evaluate(`
(async () => {
let response;
try {
response = await fetch(${JSON.stringify(apiUrl)}, { credentials: 'include' });View on GitHub (pinned to 49907e53dc)
Solutions
- Check network connectivity and confirm https://www.zhihu.com resolves in a browser.
- Relaunch/reconnect the Chrome instance backing the Browser Bridge, then rerun the command.
- Retry after a short wait — transient timeouts and connection resets are the most common cause.
- If behind a proxy/firewall, allow-list www.zhihu.com or switch networks.
Example fix
// before
await extractAnswer(page, { answerId: '12345' });
// after
try {
await extractAnswer(page, { answerId: '12345' });
} catch (err) {
if (/Failed to open Zhihu answer/.test(err.message)) {
await sleep(3000); // transient network/timeout — retry once
await extractAnswer(page, { answerId: '12345' });
} else throw err;
} Defensive patterns
Strategy: retry
Validate before calling
async function canReachZhihu() {
try {
const res = await fetch('https://www.zhihu.com/robots.txt', { method: 'HEAD' });
return res.ok || res.status < 500;
} catch { return false; }
}
if (!(await canReachZhihu())) throw new Error('zhihu.com unreachable; fix network before extracting'); Try / catch
try {
await extractAnswer(page, { answerId });
} catch (err) {
if (String(err.message).startsWith('Failed to open Zhihu answer')) {
// network/navigation failure: backoff and retry up to N times
for (let i = 1; i <= 3; i++) {
await sleep(i * 2000);
try { return await extractAnswer(page, { answerId }); } catch { /* retry */ }
}
}
throw err;
} Prevention
- Verify connectivity to www.zhihu.com before batch downloads
- Keep the Bridge-controlled Chrome instance running for the whole job
- Add exponential backoff retries around extractAnswer
- Check proxy/firewall settings if running in a corporate environment
When it happens
Trigger: Calling extractAnswer(page, { answerId }) when page.goto to www.zhihu.com/answer/<id> throws: no internet/DNS failure, Zhihu unreachable or timing out, the Browser Bridge Chrome instance is closed, or the tab was killed during navigation.
Common situations: Developer offline or behind a proxy/firewall blocking www.zhihu.com; Chrome profile used by the bridge was closed; corporate network blocks zhihu.com; transient Zhihu outage; typo in the answer id causing an immediate connection-level failure (rare, usually gives 404 instead).
Related errors
- LinkedIn people search navigation failed: ${error?.message |
- Failed to open Zhihu answer ${answerId}: ${err instanceof Er
- Failed to open Zhihu answer ${answerId}: ${err instanceof Er
- FETCH_ERROR
- archive wayback request failed: ${error?.message || error}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/23eee717379ccb7c.
Report an issue: GitHub.