microsoft/playwright · error · Error
Failed to parse response: ${text}
Error message
Failed to parse response: ${text} What it means
Thrown by the recorder Chat client (the AI assistant used by the test recorder) when the model's response cannot be JSON.parse'd after three retry attempts. Each failure appends the parse error back to the conversation to nudge the model, but if it still does not return valid JSON the client gives up.
Source
Thrown at packages/playwright-core/src/server/recorder/chat.ts:52
}
clearHistory() {
this._history = [];
}
async post<T>(prompt: string): Promise<T | null> {
await this._append('user', prompt);
let text = await asString(await this._post());
if (text.startsWith('```json') && text.endsWith('```'))
text = text.substring('```json'.length, text.length - '```'.length);
for (let i = 0; i < 3; ++i) {
try {
return JSON.parse(text);
} catch (e) {
await this._append('user', String(e));
}
}
throw new Error('Failed to parse response: ' + text);
}
private async _append(user: ChatMessage['user'], content: string) {
this._history.push({ user, content });
}
private async _connection(): Promise<Connection> {
if (!this._connectionPromise) {
this._connectionPromise = WebSocketTransport.connect(undefined, this._wsEndpoint).then(transport => {
return new Connection(transport, (method, params) => this._dispatchEvent(method, params), () => {});
});
}
return this._connectionPromise;
}
private _dispatchEvent(method: string, params: any) {
if (method === 'chatChunk') {
const { chatId, chunk } = params;View on GitHub (pinned to c8fc3bf8d3)
Solutions
- Retry the chat request (transient model non-compliance often succeeds on a new run).
- Verify the configured chat WebSocket endpoint is correct and reachable.
- Simplify the prompt so the model returns a shorter, well-formed JSON payload; if the issue persists, report it as a tooling bug since JSON conformance is the model's contract.
Defensive patterns
Strategy: retry
Try / catch
let result = null;
for (let i = 0; i < 3 && !result; ++i) {
try {
result = await chat.post('...');
} catch (e) {
if (/Failed to parse response/.test(e.message) && i < 2) continue;
throw e;
}
} Prevention
- Keep prompts concise so the model returns well-formed, non-truncated JSON.
- Verify the configured chat WebSocket endpoint is reachable and correct.
- Treat persistent parse failures as a tooling/backend bug and report them.
When it happens
Trigger: The chat/LLM endpoint returns malformed JSON, prose around JSON, code fences that are not stripped, or truncated output; the model ignores repeated 'return JSON' instructions; the WebSocket endpoint is misconfigured and returns unexpected content.
Common situations: Using the experimental AI recorder/chat with a flaky or non-conformant backend; model output exceeding token limits producing truncated JSON; network issues corrupting the streamed response.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
AI-assisted analysis of microsoft/playwright@c8fc3bf8d3 (2026-08-12).
Data as JSON: /api/errors/c00820bac2be8b19.
Report an issue: GitHub.