diff --git a/playwriter/src/mcp.ts b/playwriter/src/mcp.ts index 22d324e..cac11a3 100644 --- a/playwriter/src/mcp.ts +++ b/playwriter/src/mcp.ts @@ -133,6 +133,7 @@ async function getCurrentPage() { if (pages.length > 0) { const page = pages[0] + page.waitForEvent('load', {timeout}) await page.emulateMedia({ colorScheme: null }) return page } diff --git a/playwriter/src/prompt.md b/playwriter/src/prompt.md index 72f88a1..eaa8ac8 100644 --- a/playwriter/src/prompt.md +++ b/playwriter/src/prompt.md @@ -40,6 +40,15 @@ await state.localhostPage.bringToFront(); - try to never sleep or run `page.waitForTimeout` unless you have to. there are better ways to wait for an element - never close browser or context. NEVER call `browser.close()` +## always check the current page state after an action + +after you click a button or submit a form you ALWAYS have to then check what is the current state of the page. you cannot assume what happened after doing an action. instead run the following code to know what happened after the action: + +`console.log('url:', page.url()); console.log(await accessibilitySnapshot(page).then(x => x.slice(0, 1000)));` + +if nothing happened you may need to wait before the action completes, using something like `page.waitForNavigation({timeout: 3000})` or `await page.waitForLoadState('networkidle', {timeout: 3000})` + + ## event listeners always detach event listener you create at the end of a message using `page.removeAllListeners()` or similar so that you never leak them in future messages