The interaction feedback loop
Every browser interaction should follow an observe → act → observe loop. After every action, you must check its result before proceeding. Never chain multiple actions blindly — the page may not have responded as expected.Core loop
The fundamental pattern for all browser interactions:Observe
Print
state.page.url() and take an accessibility snapshot. Always print the URL so you know where you are — pages can redirect, and actions can trigger unexpected navigation.Check
Read the snapshot and URL. If the page isn’t ready (still loading, expected content missing, wrong URL), wait and observe again — don’t act on stale or incomplete state. Only proceed when you can identify the element to interact with.
Observe again
Print URL + snapshot to verify the action’s effect. If the action didn’t take effect (nothing changed, page still loading), wait and observe again before proceeding.
Visual diagram
Complete example
Opening a Framer plugin via the command palette. Each step is a separate execute call:Step 1: Open page and observe
Step 2: Act and observe result
Step 3: Type and observe
Step 4: Submit and observe outcome
Other ways to observe
Snapshots are the primary feedback mechanism, but some actions have side effects better observed through other channels:Console logs
Check for errors or app state after an action:Network requests
Verify API calls were made after a form submit or button click:URL changes
Confirm navigation happened:Screenshots
Only for visual layout issues (see snapshot vs screenshot in best practices):Common mistakes
Not verifying actions succeeded
Chaining actions without feedback
Using stale locators
Assuming page content loaded
Best practices
Multiple execute calls for complex tasks
Use multiple execute calls to break down complex logic — this helps understand intermediate state and isolate which action failed:Snapshot before screenshot
Always usesnapshot() first to understand page state (text-based, fast, cheap). Only use screenshot when you specifically need visual/spatial information:
Wait strategies
Prefer proper waits over arbitrary timeouts:Clean up after yourself
Pattern summary
- Always observe before and after actions — never assume
- Use snapshots as primary feedback — fast and cheap
- Break complex tasks into multiple calls — easier to debug
- Verify page state — check URL and content after navigation
- Use fresh locators — retake snapshots when page changes
- Wait for content — don’t interact with elements that may not exist
- Clean up listeners — prevent cross-session interference