agentleFS
jwrobesjwrobes/skills/playwright-capture-flow/SKILL.md

playwright-capture-flow

Skill1 starsChanged 7 months agoMITView on GitHub

Record an interactive Playwright MCP session and generate a reusable headless script from it. After completing a successful Playwright MCP flow (login, navigate, click, type, etc.), the user says: - "capture that as a script" - "turn that into a reusable script" - "graduate this to headless" - "record that flow" - "make that repeatable" Phase 1: Interactive exploration (MCP) — The agent uses Playwright MCP to walk through a flow. It navigates pages, takes snapshots, clicks elements, fills forms.…

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 3 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    After completing a successful Playwright MCP flow (login, navigate, click, type, etc.), the user says:

    line 7
  2. Distinctive:

    Look at the flow and determine what should be CLI arguments vs hard-coded:

    line 37
  3. Very specific:

    Create a new file at <your-playwright-flows-dir>/scripts/<flow-name>.js following this template.

    line 48
  4. Very specific:

    If your playwright tooling uses a dispatcher (e.g., pw <flow-name>), add the new command to its help text.

    line 122
  5. Distinctive:

    Run it once headless, once headed to verify:

    line 126
  6. Very specific:

    Critical: Always copy selectors from the "Ran Playwright code" output, not from the ref IDs.

    line 155

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Playwright: Capture Flow

Record an interactive Playwright MCP session and generate a reusable headless script from it.

When to Use

After completing a successful Playwright MCP flow (login, navigate, click, type, etc.), the user says:

  • "capture that as a script"
  • "turn that into a reusable script"
  • "graduate this to headless"
  • "record that flow"
  • "make that repeatable"

How It Works

Phase 1: Interactive exploration (MCP) — The agent uses Playwright MCP to walk through a flow. It navigates pages, takes snapshots, clicks elements, fills forms. This is the discovery phase — figuring out selectors, page structure, and the sequence of actions.

Phase 2: Capture (this skill) — After the MCP flow succeeds, the agent reviews the Playwright actions it took and generates a headless Node.js script that replays the same flow.

Procedure

Step 1: Gather the MCP action log

Review the conversation for all Playwright MCP tool calls that were part of the successful flow. Extract in order:

  • browser_navigate — URLs visited
  • browser_click — Element refs and the Playwright code that was generated (the getByRole, getByText, etc.)
  • browser_type — Element refs and text entered
  • browser_snapshot — What was visible (for assertions)
  • browser_fill_form — Form fields filled
  • browser_select_option — Dropdowns selected

The key data is in the "Ran Playwright code" section of each MCP result — that's the actual Playwright API call that worked.

Step 2: Identify parameterizable inputs

Look at the flow and determine what should be CLI arguments vs hard-coded:

Hard-codeParameterize
Selectors (role, name, placeholder)User-provided text (messages, form values)
Navigation paths (relative URLs)Account IDs, entity IDs
Wait conditionsBase URL (localhost vs staging)
Assertion patternsOutput file paths, screenshots

Step 3: Generate the script

Create a new file at <your-playwright-flows-dir>/scripts/<flow-name>.js following this template. (A common convention is ~/.local/playwright-flows/scripts/, but use whatever path makes sense for your setup.)

/**
 * <Description of what this flow does>
 *
 * Usage:
 *   node <flow-name>.js <required-args> [options]
 *
 * Output (JSON to stdout):
 *   { "success": true, "timestamp": "...", ... }
 */

const { chromium } = require('playwright');

function parseArgs() {
  const args = process.argv.slice(2);
  const opts = {
    baseUrl: 'http://localhost:3000',
    headed: false,
    timeout: 30000,
    screenshotPath: null,
    // ... flow-specific defaults
  };

  for (let i = 0; i < args.length; i++) {
    switch (args[i]) {
      case '--base-url': opts.baseUrl = args[++i]; break;
      case '--headed': opts.headed = true; break;
      case '--timeout': opts.timeout = parseInt(args[++i], 10); break;
      case '--screenshot': opts.screenshotPath = args[++i]; break;
      // ... flow-specific args
    }
  }

  // Validate required args
  return opts;
}

async function runFlow(opts) {
  const timestamp = new Date().toISOString();
  const browser = await chromium.launch({ headless: !opts.headed });
  const context = await browser.newContext();
  const page = await context.newPage();

  try {
    // Paste the MCP "Ran Playwright code" steps here, adapted:
    // - Replace page.goto('http://localhost:3000/...') with template literals using opts.baseUrl
    // - Add waitFor() before interactions for reliability
    // - Add try/catch for assertions

    // Return structured result
    return { success: true, timestamp, /* ... flow-specific output */ };

  } catch (err) {
    if (opts.screenshotPath) {
      await page.screenshot({ path: opts.screenshotPath, fullPage: true }).catch(() => {});
    }
    return { success: false, timestamp, error: err.message, url: page.url() };
  } finally {
    await browser.close();
  }
}

(async () => {
  const opts = parseArgs();
  const result = await runFlow(opts);
  console.log(JSON.stringify(result, null, 2));
  process.exit(result.success ? 0 : 1);
})();

Step 4: Register in the dispatcher

If your playwright tooling uses a dispatcher (e.g., pw <flow-name>), add the new command to its help text. A typical pattern is auto-discovery of scripts/<name>.js so no code change is required.

Step 5: Test the generated script

Run it once headless, once headed to verify:

# Headless
node <your-playwright-flows-dir>/scripts/<flow-name>.js <args>

# Headed (visual verification)
node <your-playwright-flows-dir>/scripts/<flow-name>.js <args> --headed

Step 6: Report to user

Show the user:

  • The script path
  • The command to run it
  • The JSON output format
  • What was parameterized vs hard-coded

Translation Rules: MCP to Playwright Script

MCP tool callScript equivalent
browser_navigate({ url })await page.goto(url, { waitUntil: 'networkidle' })
browser_click({ ref }) + "Ran: page.getByRole(...).click()"Copy the getByRole call directly, add waitFor before it
browser_type({ ref, text }) + "Ran: page.getByRole(...).fill(...)"Copy the getByRole + fill call directly
browser_snapshot showing text X visibleawait expect(page.getByText('X')).toBeVisible() or page.getByText('X').isVisible()
browser_wait_for({ time: N })await page.waitForTimeout(N * 1000)
browser_press_key({ key })await page.keyboard.press(key)

Critical: Always copy selectors from the "Ran Playwright code" output, not from the ref IDs. The refs are ephemeral — the getByRole/getByText calls are stable.

Reference Pattern

A well-formed flow script typically demonstrates: argument parsing (positional + flag), explicit error handling, JSON-on-stdout for downstream tooling, optional screenshot support for visual verification, and a clean exit code (0 on success, 1 on failure).

Naming Convention

Scripts are named by their action: send-message.js, check-inbox.js, login-as-user.js, verify-notification.js. Use kebab-case. If your dispatcher auto-discovers scripts by filename, the action name doubles as the command.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.