---
name: browser-interact
description: Drive a real browser during frontend work — verify a change rendered, click through a flow, fill forms, read console errors, take screenshots, or debug performance/memory/network. Use whenever interacting with a local web app in a browser (Playwright script templates, chrome-devtools tradeoffs, SPA mock-API gotchas).
title: browser-interact
canonical_url: https://skilld.dev/gh/david-crespo/dotfiles/browser-interact
last_updated: 2026-10-27T15:12:45.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [react-render-hook.js](https://skilld.dev/api/skills-raw/david-crespo/dotfiles/browser-interact/react-render-hook.js).
>
> If the user asked to install this Skill, run `npx skilld install david-crespo/dotfiles/browser-interact`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/browser-interact`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/david-crespo/dotfiles/browser-interact) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/browser-interact`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/browser-interact --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/browser-interact --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

How to interact with a browser during frontend dev work.

## Default: one Playwright script per check

For any multi-step flow (load a page, click around, fill a form, verify a
change), write a Playwright script and run it with `node`. Driving the browser
action-by-action through MCP tools costs a full model round trip per action: a
~25-action flow takes minutes through MCP calls and ~5 seconds as one script.

One-shot scripts are fine — headless chromium launches in ~70ms, so the app's
own load time dominates. Don't set up a persistent browser server
(`launchServer`/`connect` saves CPU, not wall-clock) unless running many
checks in a tight loop.

### Template

```js
import { chromium } from 'playwright'
const browser = await chromium.launch()
// 2x so screenshots match a Retina display; 1x looks half-res to the user
const page = await browser.newPage({ deviceScaleFactor: 2 })

await page.goto('http://localhost:4444/projects', { waitUntil: 'domcontentloaded' })
// wait on a real element, never 'networkidle'
await page.getByRole('link', { name: 'New project' }).waitFor()

// interact by accessible role/name; crib selectors from the repo's e2e tests
await page.getByRole('link', { name: 'New project' }).click()
await page.getByRole('textbox', { name: 'Name' }).fill('my-project')
await page.getByRole('button', { name: 'Create project' }).click()
await page.waitForURL('**/projects/my-project/instances')

// verify created state via CLIENT-SIDE nav — see mock-API gotcha below
await page
  .getByRole('navigation', { name: 'Breadcrumbs' })
  .getByRole('link', { name: 'Projects' })
  .click()

console.log(await page.locator('body').ariaSnapshot()) // ~3KB page summary
await page.screenshot({ path: 'check.png' })

// console/errors are readable retroactively (Playwright 1.61+, last 200 msgs;
// filter: 'since-navigation' scopes to after the last full page load)
for (const m of await page.consoleMessages()) console.log(`[${m.type()}] ${m.text()}`)
for (const e of await page.pageErrors()) console.log(`[pageerror] ${e.message}`)
await browser.close()
```

### Gotchas (each of these caused a first-run failure in testing)

- **Module resolution**: ESM ignores `NODE_PATH`. Run the script from inside
  the frontend repo (most already have `@playwright/test`), or symlink the
  repo's `node_modules` next to the script. If chromium isn't cached in
  `~/Library/Caches/ms-playwright`, ask before downloading it.
- **SPA + in-memory mock API (MSW etc.)**: any full page load — `page.goto`,
  reload, URL navigation — reboots the service worker and resets the mock DB,
  wiping state created earlier in the flow. Verify mutations by navigating
  in-app via clicks.
- **Waiting**: wait on a specific element at the destination, not
  `networkidle` (SPAs may never go idle) and not `location.pathname` (URL
  updates before the destination renders). After a mutation, `waitForURL` is
  reliable.
- **Strict mode**: ambiguous selectors throw (e.g. a "Projects" link in both
  breadcrumb and sidebar). Scope through a parent
  (`getByRole('navigation', { name: ... }).getByRole(...)`).
- **Selectors**: prefer role + accessible name. If the repo has e2e tests,
  copy their selectors instead of guessing; otherwise print an
  `ariaSnapshot()` first and pick names from it.
- **Page summary**: `page.locator('body').ariaSnapshot()` (~3KB) instead of
  dumping HTML. Screenshots go to files; Read them after.
- **Screenshot resolution**: any screenshot the user will look at must be taken
  at `deviceScaleFactor: 2` (default is 1, which looks half-res on their
  display). In a Playwright test file, use `test.use({ deviceScaleFactor: 2 })`.
  Prefer `locator.screenshot()` on the relevant element (a dialog, a card) over
  a full-page shot.

## When to use browser MCP tools instead

For a one-off interactive look at a page that's already up — a screenshot,
reading console errors, a single click. Per-call latency is only 1–3s; it's
the per-action round trips that make long flows slow. (The `chrome-devtools`
CLI has the same tradeoff: ~0.2s fixed overhead per invocation, so idiomatic
one-command-per-action scripts run ~2x slower than Playwright; batching
everything into `evaluate_script` blobs matches Playwright's speed but is
worse to write.)

## Debugging: pick by job

chrome-devtools MCP/CLI is uniquely capable where it vendors DevTools' own
analysis code (unreachable via Playwright or raw CDP):

- **Performance traces**: `performance_start_trace` / `performance_analyze_insight`
  run DevTools' trace engine — LCP breakdown, CWV insights.
- **Heap analysis**: CLI with `--memoryDebugging` exposes dominator trees,
  retainer paths, duplicate strings, snapshot comparison.
- **Console stacks**: auto-symbolicated through source maps.
- **The user's real Chrome**: `--autoConnect` (Chrome ≥144) attaches to the
  actual logged-in default-profile browser — useful when the bug needs real
  app state.

Playwright is better for **network debugging**: `request.timing()` gives
per-request DNS/connect/TLS/TTFB/download breakdowns, plus route
interception/mocking and HAR record/replay. The chrome-devtools network tools
are inspection-only, with no per-request timing. (Playwright's
`context.newCDPSession(page)` also reaches any raw CDP domain if needed.)

## React re-render questions (does this `memo` do anything?)

Three different questions, three tools. All verified by driving a React 19 +
Vite app from Playwright; none needs a browser extension.

- **Who rendered, how often?** `react-render-hook.js` (next to this file), a
  ~60-line stand-in for React DevTools installed via
  `page.addInitScript({ path })`. Zero deps, no app edits. Usage and gotchas
  are in its header comment. react-scan's programmatic API returns the same
  names and counts plus self time, but costs an install and an entry-point
  import, and its change/unnecessary reporting is dead in the `onRender`
  callback (0.5.7). Not worth it over the hook.
- **Does it matter?** Wrap the root in `<Profiler id="x" onRender={...}>` and
  push `{ actualDuration, baseDuration }` to a window array. `baseDuration`
  is the cost if nothing bailed out, `actualDuration` is what actually ran,
  so the gap is exactly what memoization saved for that commit. One edit at
  the app entry; the only tool here that yields a number worth deciding on.
- **Why did a memo'd component re-render?** why-did-you-render, with a
  `notifier` that pushes `reason.propsDifferences` to a window array. It
  names the prop (e.g. `onSelect: function`) or reports an owner-only
  re-render (memo missing). On React 19 it must be the JSX import source:
  `react({ jsxImportSource: '@welldone-software/why-did-you-render' })` in
  the Vite config, gated on an env var, plus a first import that calls
  `whyDidYouRender(React, { trackAllPureComponents: true, notifier })`.
  Silent when nothing was avoidable, which is the right answer.

Long-animation-frame / long-task entries are too coarse for this (50ms
threshold); a 20ms wasted re-render never shows up.
