Problem/Motivation
browser_preview opens each page in a throwaway browser — it cannot walk a multi-page flow (open a Drupal Canvas page, go back, go forward, reload) and it re-establishes login on every single call. An AI agent verifying a build across several pages loses its session and its navigation history between calls, so it cannot reliably check things like "does Back/Forward keep the authenticated session and the right page in history".
Proposed resolution
Add a browser_navigate AI Agent tool plus a stateful navigation runner that persists the browser session (cookies via Playwright storageState) and a navigation history stack in a per-user state file between calls.
One action per call:
{"type":"goto","url":"/page/12"}{"type":"back"}{"type":"forward"}{"type":"reload"}- or an interaction:
click/type/scroll/wait/resize
Login is established once and reused across calls. The chat conversation itself is untouched because navigation runs in a separate headless browser, not the user's own browser tab. The tool returns the screenshot file id, page title, visible text, console errors, and the history position (canGoBack / canGoForward).
Same use ai playwright permission gate and same-host URL guard as browser_preview.
Implementation:
scripts/browser-navigate.mjs: restoresstorageState+ history from a state file, performs one goto/back/forward/reload or interaction, saves state back, returns url/title/text/console/screenshot/history/index/canGoBack/canGoForward.PlaywrightRunner::navigate(): resolves goto URLs (same host guard ascapture()), runs the script per acting user, saves the screenshot as a managed file, returns the structured result.BrowserNavigate#[FunctionCall]tool: oneactionJSON argument; same permission gate asbrowser_preview.
Verified locally: goto -> goto -> back -> forward -> reload keeps an authenticated session and correct history across separate process calls; each step saves a screenshot file. phpcs (Drupal + DrupalPractice) is clean.
Remaining tasks
- ✅ File an issue about this project
- ✅ Addition/Change/Update/Fix to this project
- ✅ Testing to ensure no regression
- ➖ Automated unit/functional testing coverage
- ➖ Developer Documentation support on feature change/addition
- ➖ User Guide Documentation support on feature change/addition
- ➖ UX/UI designer responsibilities
- ➖ Accessibility and Readability
- ❌ Reviewed by a human
- ❌ Code review by maintainers
- ❌ Full testing and approval
- ❌ Credit contributors
- ❌ Review with the product owner
- ❌ Update Release Notes
- ❌ Release
User interface changes
- N/A
API changes
- N/A
Data model changes
- N/A
Release notes snippet
- N/A
Issue fork ai_playwright-3608867
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments