Skip to content

Commit 3579009

Browse files
committed
chore(mcp): do not render page state when snapshot has not changed
1 parent 7249e20 commit 3579009

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

packages/playwright/src/mcp/browser/response.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,16 @@ function renderTabSnapshot(tabSnapshot: TabSnapshot, options: { omitSnapshot?: b
187187
lines.push('');
188188
}
189189

190-
lines.push(`### Page state`);
191-
lines.push(`- Page URL: ${tabSnapshot.url}`);
192-
lines.push(`- Page Title: ${tabSnapshot.title}`);
193-
lines.push(`- Page Snapshot:`);
194-
lines.push('```yaml');
195-
// TODO: perhaps not render page state when there are no changes?
196-
lines.push(options.omitSnapshot ? '<snapshot>' : (tabSnapshot.ariaSnapshot || '<no changes>'));
197-
lines.push('```');
190+
if (tabSnapshot.ariaSnapshot) {
191+
// Snapshot (diff) can be empty when nothing has changed.
192+
lines.push(`### Page state`);
193+
lines.push(`- Page URL: ${tabSnapshot.url}`);
194+
lines.push(`- Page Title: ${tabSnapshot.title}`);
195+
lines.push(`- Page Snapshot:`);
196+
lines.push('```yaml');
197+
lines.push(options.omitSnapshot ? '<snapshot>' : tabSnapshot.ariaSnapshot);
198+
lines.push('```');
199+
}
198200

199201
return lines.join('\n');
200202
}

tests/mcp/snapshot-diff.spec.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,7 @@ test('should return aria snapshot diff', async ({ client, server }) => {
6363
ref: 'e3',
6464
},
6565
})).toHaveResponse({
66-
pageState: expect.stringContaining(`Page Snapshot:
67-
\`\`\`yaml
68-
<no changes>
69-
\`\`\``),
66+
pageState: expect.not.stringContaining(`Page Snapshot`),
7067
});
7168

7269
expect(await client.callTool({

0 commit comments

Comments
 (0)