Clarify script generation guidelines for UI-only interactions#10
Merged
DeDuckProject merged 1 commit intomainfrom Mar 12, 2026
Merged
Conversation
Add two rules to the script generation prompt that guide the LLM to behave like a real user: only use standard Playwright actions and never inject JS/CSS into the page. This prevents scripts from "faking" features (e.g. re-implementing mouse cursor overlays) instead of exercising the actual application code. https://claude.ai/code/session_01UQthhi9Ez6uoif4UVAb1sL
🎬 UI Demo PreviewChanges detected in: What changed: No visible UI changes were made. This diff updates internal prompt instructions for the script generator, restricting it to real user interactions via Playwright and prohibiting code injection into the page. Demo script (auto-generated)import type { Page } from '@playwright/test';
export async function demo(page: Page): Promise<void> {
await page.goto('http://localhost:3000', { waitUntil: 'networkidle' });
await page.waitForLoadState('networkidle');
await page.waitForTimeout(1500);
// Look for a diff or code input area and fill it with a sample diff
const diffInput = page.locator('textarea').first();
await diffInput.click();
await diffInput.fill(`diff --git a/src/button.tsx b/src/button.tsx
index 1234567..abcdefg 100644
--- a/src/button.tsx
+++ b/src/button.tsx
@@ -1,5 +1,10 @@
export function Button({ label }: { label: string }) {
- return <button>{label}</button>;
+ return (
+ <button
+ className="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600"
+ onClick={() => console.log('clicked')}
+ >
+ {label}
+ </button>
+ );
}`);
await page.waitForTimeout(1500);
// Try to find and click a generate button
const generateButton = page.getByRole('button', { name: /generate/i }).first();
const hasGenerateButton = await generateButton.isVisible().catch(() => false);
if (hasGenerateButton) {
await generateButton.click();
await page.waitForLoadState('networkidle');
await page.waitForTimeout(2000);
} else {
// Try submit or run button
const submitButton = page.getByRole('button').first();
const hasSubmit = await submitButton.isVisible().catch(() => false);
if (hasSubmit) {
await submitButton.click();
await page.waitForLoadState('networkidle');
await page.waitForTimeout(2000);
}
}
// Observe the generated output area
const outputArea = page.locator('pre, code, [data-testid="output"], .output').first();
const hasOutput = await outputArea.isVisible().catch(() => false);
if (hasOutput) {
await outputArea.scrollIntoViewIfNeeded();
await page.waitForTimeout(1500);
// Check output text to visually confirm it uses standard Playwright actions
const outputText = await outputArea.textContent().catch(() => '');
const hasNavigate = outputText?.includes('goto') || outputText?.includes('navigate');
const hasClick = outputText?.includes('click');
if (hasNavigate || hasClick) {
await page.waitForTimeout(1500);
}
}
// Scroll through the page to show the result
await page.evaluate(() => window.scrollTo({ top: document.body.scrollHeight / 2, behavior: 'smooth' }));
await page.waitForTimeout(1500);
await page.evaluate(() => window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' }));
await page.waitForTimeout(1500);
await page.evaluate(() => window.scrollTo({ top: 0, behavior: 'smooth' }));
await page.waitForTimeout(1000);
}Generated by git-glimpse |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Updated the script generation prompt to provide clearer guidance on how generated Playwright scripts should interact with applications, emphasizing user-like behavior through the UI only.
Key Changes
page.evaluate,page.addInitScript, inline<script>/<style>tags) to prevent scripts from simulating application featuresDetails
These changes reinforce best practices for generated test/demo scripts by ensuring they:
https://claude.ai/code/session_01UQthhi9Ez6uoif4UVAb1sL