# Playwright vs paprika3d for a three.js canvas: one worked example
https://paprika3d.com/docs/guides/playwright-vs-paprika3d

The same three.js WebGL scene tested with Playwright alone and with paprika3d. Both drive headless Chrome at 1280 by 800 on a rover pad with two real scene defects (coplanar z-fighting and a mesh behind the camera): Playwright checks the DOM, console errors and real-time input, while paprika3d reads the named meshes on screen, flags both defects and steps input on a paused 1/60 s clock.

**Install:** in Claude Code, `claude plugin marketplace add Keeno-Corp/paprika3d` then `claude plugin install paprika3d@paprika3d`; in any other MCP client, the server `npx -y paprika3d serve` ([every agent](https://paprika3d.com/docs/install)).

Testing a three.js `<canvas>` with Playwright alone and testing the same scene with paprika3d answer different halves of the problem. On the rover pad below, Playwright verifies the HTML overlay, checks for zero console errors, clicks at viewport coordinates and runs keyboard input in real time. paprika3d opens the same page on a paused 1/60 s clock, lists every named mesh on screen with its pixel box, flags a coplanar z-fighting stripe and a mesh placed behind the camera, names the mesh under a click and traces movement to the exact frame.

In Claude Code, install paprika3d with `claude plugin marketplace add Keeno-Corp/paprika3d` and `claude plugin install paprika3d@paprika3d`; in Codex, Cursor, Gemini CLI or another MCP client, register `npx -y paprika3d serve`.

## At a glance: same scene, two runs

Both runs drove the exact `index.html` below in headless Chrome at 1280 by 800 on 2026-11-30 (Playwright `playwright-core` 1.65.1 and paprika3d 0.4.5, software WebGL via SwiftShader).

| Check on the rover pad | Playwright alone | paprika3d |
|---|---|---|
| What is inside `<canvas>` | `ariaSnapshot()` returns the `#hud` text and no canvas children; `boundingBox()` returns the 1280 by 800 rectangle | `look` lists all 5 visible named meshes with screen share and pixel box (`floor`, `padStripe`, `beacon`, `rover`, `crate`) |
| Coplanar z-fighting (`padStripe` on `floor` at `y = 0`) | 0 console errors; silent in DOM and script assertions | `look` flags the shared face plane (`y = 0.00`) between `floor` and `padStripe` and gives the minimum offset (`0.00013 units`) |
| Off-camera mesh (`spareBeacon` at `z = 14`) | 0 console errors; absent from screenshot with no warning | `look` reports `Never visible: spareBeacon (1.4 units, behind the camera)` |
| Clicking `beacon` | `page.mouse.click(960, 380)` uses hand-picked pixel coordinates and returns `void` | `interact` clicks the center `(942, 367)` of `beacon`'s box from `look` and replies `over beacon (Mesh, 10.2 units)` |
| Driving `rover` into `crate` | `waitForTimeout(1000)` ran 84 frames on run 1 and 105 frames on run 2 | `interact` with `until` hit `collected == 1` at frame 54 on the paused 1/60 s clock, repeatable on every run |
| Confirming `crate` disappeared | Needs `window.__game` or a pixel diff | `look` drops `crate` from `On screen (4)` and reports `3%` of the picture changed |
| Renderer counts and errors | Custom `page.evaluate` hook required | `observe` returns game state JSON, draw calls (`4`), triangles (`112`), geometries (`5`), programs (`2`) and console errors (`[]`) |

## The scene

A rover pad with five visible meshes (`floor`, `padStripe`, `rover`, `crate`, `beacon`), an HTML HUD (`#hud`), and two real defects that produce zero JavaScript or WebGL errors:

1. `padStripe` sits at `y = 0`, flush on `floor` at `y = 0`, so the two surfaces z-fight as the camera moves.
2. `spareBeacon` sits at `z = 14`, behind the camera at `(0, 4.2, 9.5)`, so it is in the scene graph and never drawn.

`ArrowRight` drives the rover into the crate to collect it; clicking the beacon selects it via `THREE.Raycaster`. Save as `index.html` and run `npm install three` in the same folder.

```html
<!-- verify -->
<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>Rover Pad</title>
  <style>
    html, body { margin: 0; overflow: hidden; background: #18202c; font-family: system-ui, sans-serif; }
    canvas { display: block; }
    #hud { position: fixed; top: 12px; left: 16px; color: #eef2f7; font-size: 18px; }
  </style>
</head>
<body>
  <div id="hud">Collected: 0 / 1</div>
  <script type="importmap">{"imports":{"three":"./node_modules/three/build/three.module.js"}}</script>
  <script type="module">
    import * as THREE from 'three';

    const renderer = new THREE.WebGLRenderer({ antialias: true });
    renderer.setSize(innerWidth, innerHeight);
    renderer.toneMapping = THREE.ACESFilmicToneMapping;
    document.body.appendChild(renderer.domElement);

    const scene = new THREE.Scene();
    scene.background = new THREE.Color(0x18202c);
    const camera = new THREE.PerspectiveCamera(45, innerWidth / innerHeight, 0.1, 100);
    camera.position.set(0, 4.2, 9.5);
    camera.lookAt(0, 0.3, 0);

    scene.add(new THREE.HemisphereLight(0xdce8ff, 0x2a3342, 1.8));
    const sun = new THREE.DirectionalLight(0xfff4dd, 2.2);
    sun.position.set(4, 8, 5);
    scene.add(sun);

    const floor = new THREE.Mesh(
      new THREE.PlaneGeometry(12, 8).rotateX(-Math.PI / 2),
      new THREE.MeshStandardMaterial({ color: 0x334155, roughness: 0.85 })
    );
    floor.name = 'floor';
    scene.add(floor);

    // Bug 1: painted stripe sits on y = 0, the same plane as floor (z-fighting).
    const padStripe = new THREE.Mesh(
      new THREE.PlaneGeometry(8, 1.1).rotateX(-Math.PI / 2),
      new THREE.MeshStandardMaterial({ color: 0xeab308, roughness: 0.7 })
    );
    padStripe.name = 'padStripe';
    scene.add(padStripe);

    const rover = new THREE.Mesh(
      new THREE.BoxGeometry(0.9, 0.55, 0.7),
      new THREE.MeshStandardMaterial({ color: 0x3b82f6, roughness: 0.45 })
    );
    rover.name = 'rover';
    rover.position.set(-2.5, 0.28, 0);
    scene.add(rover);

    const crate = new THREE.Mesh(
      new THREE.BoxGeometry(0.65, 0.65, 0.65),
      new THREE.MeshStandardMaterial({ color: 0x22c55e, roughness: 0.5 })
    );
    crate.name = 'crate';
    crate.position.set(0.5, 0.33, 0);
    scene.add(crate);

    const beaconMat = new THREE.MeshStandardMaterial({ color: 0xf97316, roughness: 0.4 });
    const beacon = new THREE.Mesh(new THREE.CylinderGeometry(0.32, 0.42, 1.4, 24), beaconMat);
    beacon.name = 'beacon';
    beacon.position.set(3.2, 0.7, 0);
    scene.add(beacon);

    // Bug 2: a spare beacon placed behind the camera (z = 14); in the scene, never drawn.
    const spareBeacon = new THREE.Mesh(
      new THREE.CylinderGeometry(0.32, 0.42, 1.4, 24),
      new THREE.MeshStandardMaterial({ color: 0xec4899, roughness: 0.4 })
    );
    spareBeacon.name = 'spareBeacon';
    spareBeacon.position.set(0, 0.7, 14);
    scene.add(spareBeacon);

    const hud = document.getElementById('hud');
    const held = new Set();
    const state = { x: -2.5, collected: 0, selected: null, frames: 0 };

    function act({ key, down = true }) {
      if (down) held.add(key); else held.delete(key);
    }
    addEventListener('keydown', (e) => act({ key: e.key, down: true }));
    addEventListener('keyup', (e) => act({ key: e.key, down: false }));

    const ray = new THREE.Raycaster();
    renderer.domElement.addEventListener('pointerdown', (e) => {
      const ndc = new THREE.Vector2((e.clientX / innerWidth) * 2 - 1, -(e.clientY / innerHeight) * 2 + 1);
      ray.setFromCamera(ndc, camera);
      const hit = ray.intersectObject(beacon);
      if (hit.length) {
        state.selected = 'beacon';
        beaconMat.emissive.setHex(0x663300);
      }
    });

    addEventListener('resize', () => {
      renderer.setSize(innerWidth, innerHeight);
      camera.aspect = innerWidth / innerHeight;
      camera.updateProjectionMatrix();
    });

    let last = null;
    renderer.setAnimationLoop((now) => {
      const dt = last === null ? 1 / 60 : Math.min((now - last) / 1000, 0.1);
      last = now;
      state.frames++;
      const dir = (held.has('ArrowRight') ? 1 : 0) - (held.has('ArrowLeft') ? 1 : 0);
      state.x = Math.max(-4.5, Math.min(4.5, state.x + dir * 2.4 * dt));
      rover.position.x = state.x;
      if (!state.collected && Math.abs(state.x - crate.position.x) < 0.85) {
        state.collected = 1;
        crate.visible = false;
        hud.textContent = 'Collected: 1 / 1';
      }
      renderer.render(scene, camera);
    });

    const round = (n) => +n.toFixed(2);
    window.__game = {
      describe: () => ({
        name: 'rover pad',
        keys: { ArrowRight: 'drive right', ArrowLeft: 'drive left' },
        mouse: 'click the beacon to select it',
      }),
      observe: () => ({
        rover: { x: round(state.x) },
        collected: state.collected,
        selected: state.selected,
        frames: state.frames,
        hud: hud.textContent,
      }),
      act,
      setState: (s) => {
        if (s.x !== undefined) state.x = s.x;
        if (s.collected !== undefined) {
          state.collected = s.collected;
          crate.visible = !state.collected;
          hud.textContent = `Collected: ${state.collected} / 1`;
        }
      },
    };
  </script>
</body>
</html>
```

## Run 1: testing the scene with Playwright alone

This script opens `index.html` twice in headless Chrome (`playwright-core` 1.65.1) at 1280 by 800, records console errors, inspects the canvas box and accessibility snapshot, takes a screenshot, holds `ArrowRight` for `1000 ms`, clicks `(960, 380)` to select the beacon, and reads `window.__game.observe()`.

```js
import { chromium } from 'playwright-core';

const browser = await chromium.launch({ headless: true });

async function runOnce(url, label) {
  const page = await browser.newPage({ viewport: { width: 1280, height: 800 } });
  const errors = [];
  page.on('pageerror', (e) => errors.push(e.message));
  page.on('console', (m) => { if (m.type() === 'error') errors.push(m.text()); });

  await page.goto(url, { waitUntil: 'networkidle' });
  await page.waitForTimeout(200);

  const canvasCount = await page.locator('canvas').count();
  const canvasBox = await page.locator('canvas').boundingBox();
  const aria = await page.locator('body').ariaSnapshot();
  await page.screenshot({ path: `${label}-before.png` });

  await page.keyboard.down('ArrowRight');
  await page.waitForTimeout(1000);
  await page.keyboard.up('ArrowRight');

  const stateAfterDrive = await page.evaluate(() => window.__game.observe());

  await page.mouse.click(960, 380);
  await page.waitForTimeout(100);
  const stateAfterClick = await page.evaluate(() => window.__game.observe());

  await page.screenshot({ path: `${label}-after.png` });
  await page.close();
  return { canvasCount, canvasBox, aria, stateAfterDrive, stateAfterClick, errors };
}
```

### What Playwright returned

Here is the JSON the script printed on 2026-11-30 across two consecutive runs against the same local server:

```json
{
  "run1": {
    "canvasCount": 1,
    "canvasBox": { "x": 0, "y": 0, "width": 1280, "height": 800 },
    "aria": "- text: \"Collected: 0 / 1\"",
    "stateAfterDrive": { "rover": { "x": -0.06 }, "collected": 1, "selected": null, "frames": 84, "hud": "Collected: 1 / 1" },
    "stateAfterClick": { "rover": { "x": -0.06 }, "collected": 1, "selected": "beacon", "frames": 91, "hud": "Collected: 1 / 1" },
    "errors": []
  },
  "run2": {
    "canvasCount": 1,
    "canvasBox": { "x": 0, "y": 0, "width": 1280, "height": 800 },
    "aria": "- text: \"Collected: 0 / 1\"",
    "stateAfterDrive": { "rover": { "x": -0.06 }, "collected": 1, "selected": null, "frames": 105, "hud": "Collected: 1 / 1" },
    "stateAfterClick": { "rover": { "x": -0.06 }, "collected": 1, "selected": "beacon", "frames": 112, "hud": "Collected: 1 / 1" },
    "errors": []
  }
}
```

Every assertion in the script is green: `canvasCount` is 1, `errors` is `[]`, `collected` is `1`, `selected` is `"beacon"`, and `#hud` updated to `"Collected: 1 / 1"`. Three things stand out in that output:

- **The DOM stops at `<canvas>`.** `ariaSnapshot()` contains the `#hud` div and no entries for `floor`, `padStripe`, `rover`, `crate`, `beacon` or `spareBeacon`. Without `window.__game` wired into the page, the script reads the `#hud` text and saves PNGs.
- **Both scene defects stayed silent.** Neither the coplanar `padStripe` nor the off-camera `spareBeacon` emits a console error, so the run exited 0 with both defects intact.
- **Wall-clock waits vary in frame count.** The same `1000 ms` hold of `ArrowRight` stepped `84 frames` on run 1 and `105 frames` on run 2. On a physics or collision test where step count matters, a real-time wait lands on different frames between runs and between machines.

## Run 2: testing the exact same scene with paprika3d

These replies came from paprika3d 0.4.5 over MCP stdio on the exact same `index.html` on 2026-11-30 (the run folder path is shortened to `<run>`, and helper-file lines from `open` are omitted).

**1. Open the page.** `open` serves the folder, launches headless Chrome, pauses the clock at frame 0, and returns `describe()`:

```text
open {"url": "index.html", "cwd": "<project>"}

Opened http://127.0.0.1:33513/index.html in 0.3 s, paused at frame 0.
Page text outside the canvas: 0 h1, 0 h2, 4 words
{"name":"rover pad","keys":{"ArrowRight":"drive right","ArrowLeft":"drive left"},"mouse":"click the beacon to select it"}
Next: `look` to see it, then `interact` for each interaction the request names.
```

**2. Inspect the scene with `look`.** One call takes the screenshot, checks the HTML overlay, lists every named mesh on screen with its pixel box, and catches both defects immediately:

```text
look {}

Picture: <run>/look-1.png
Pixels: brightness 17%, colour saturation 48%, 0% near black, 0% blown out.
Hues: blue 96% of the frame; over the objects (39.4% of it): blue 90%, yellow 6%.
Canvas: 1280x800 buffer for 1280x800 CSS at DPR 1 (renderer pixel ratio 1); resize handler ran.
Surfaces: "floor" and "padStripe" share a face plane (y = 0.00) over 1.1 × 8 units: they flicker as the camera moves (z-fighting). Move one at least 0.00013 units off the plane (what the depth buffer can tell apart at 10 units from this camera, and more from farther away), give the top one material.polygonOffset = true with polygonOffsetFactor -1, or remove the hidden face.
Surface: "floor" covers 35% with almost no detail (0.01 of 255): it reads as flat colour. Unless the user asked for flat colour, add texture, normal detail or lighting variation.
HTML over the canvas: 1 (div via page), 0 overlap, 0 off-screen, 0 cut off: div#hud "Collected: 0 / 1" [16, 12, 151, 32].
On screen (5):
floor 35% [0, 315, 1279, 659] 12 × 8 units
padStripe 2.3% [249, 406, 1030, 447] 8 × 1.1 units, across the view
beacon 1.1% [897, 292, 986, 441]
rover 0.69% [351, 366, 454, 438]
crate 0.5% [656, 358, 720, 437]
Never visible: spareBeacon (1.4 units, behind the camera)
```

- **Bug 1 caught:** `Surfaces` names `"floor"` and `"padStripe"`, the shared plane (`y = 0.00`), the overlap (`1.1 × 8 units`), and the depth-buffer offset (`0.00013 units` at `10 units` from the camera).
- **Bug 2 caught:** `Never visible` names `spareBeacon` and gives the cause (`behind the camera`).
- **Click target given:** `beacon` is at `[897, 292, 986, 441]`, so its center is `(942, 367)` with no guesswork.

**3. Click the beacon and drive the rover on exact frames.** `interact` clicks `(942, 367)`, confirms which mesh was under the pointer, then holds `ArrowRight` with `until` until `collected == 1` and takes a second `look`:

```text
interact {"steps": [{"mouse": "click", "x": 942, "y": 367}, {"wait": 2}]}

{"changed":{"selected":"beacon","frames":4}}
mouse click at (942, 367): over beacon (Mesh, 10.2 units)

interact {"steps": [{"key": "ArrowRight", "down": true}, {"until": {"collected": 1}, "max": 120}, {"key": "ArrowRight", "down": false}], "trace": ["rover.x", "collected"], "look": true}

{"changed":{"rover":{"x":-0.34},"collected":1,"frames":59,"hud":"Collected: 1 / 1"}}
until: collected == 1 held at frame 54
rover.x: -2.5 → -0.34 at frame 54; first changed at frame 1
collected: 0 → 1 at frame 54; first changed at frame 54
Picture: <run>/look-2.png
Pixels, Hues: as the last look; 3% of the picture changed since it.
Surfaces, Surface: the same 2 lines as the last look, still open.
HTML over the canvas: 1 (div via page), 0 overlap, 0 off-screen, 0 cut off: div#hud "Collected: 1 / 1" [16, 12, 151, 32].
On screen (4):
floor 35% [0, 315, 1279, 659] 12 × 8 units
padStripe 2.5% [249, 406, 1030, 447] 8 × 1.1 units, across the view
beacon 1.1% [897, 292, 986, 441]
rover 0.62% [563, 366, 650, 438]
Never visible: spareBeacon (1.4 units, behind the camera)
```

The click line confirms `over beacon (Mesh, 10.2 units)`. The `trace` reports `collected: 0 → 1` at frame 54, with `rover.x` at `-0.34`. Because every frame is 1/60 s on the paused clock, the same steps reach frame 54 and `-0.34` on every run. In the second `look`, `On screen` drops from 5 to 4 (`crate` is gone), `rover`'s pixel box shifts right to `[563, 366, 650, 438]`, and `3%` of the picture changed. Add `"expect": {"collected": 1}` and `"save": "collect crate"` to that `interact` call and `test` reruns it after every edit.

**4. Read state and renderer counts with `observe`.** One call returns the game state, renderer stats, scene counts and console errors together:

```text
observe {}

{"rover":{"x":-0.34},"collected":1,"selected":"beacon","frames":59,"hud":"Collected: 1 / 1","harness":{"frame":59,"renderer":{"calls":4,"triangles":112,"textures":1,"geometries":5,"programs":2},"scene":{"objects":8,"meshes":6,"lights":2,"cameras":0},"errors":[],"changed":null}}
```

## When to use Playwright, paprika3d, or both

- **Use Playwright** for multi-page user flows, authentication, forms, network interception, cross-browser CI suites and testing HTML around the canvas.
- **Use paprika3d** when a coding agent is building, debugging or playtesting a three.js, React Three Fiber or WebGL scene and needs to know which meshes drew, which ones stayed off-camera, whether faces z-fight, what a click hit, and whether inputs produce repeatable state on a paused 1/60 s clock.
- **Use both together** by keeping `window.__game` in the page: paprika3d reads it during the agent's build loop (and still lists named meshes when `window.__game` is absent), while a Playwright CI suite calls `page.evaluate(() => window.__game.observe())` alongside its DOM checks.

## Related

- [A Playwright alternative for three.js and WebGL pages built by agents](https://paprika3d.com/docs/guides/playwright-alternative-threejs-webgl): how paprika3d maps browser-test tasks to scene-aware MCP calls.
- [Chrome DevTools MCP vs Playwright MCP on a canvas/WebGL page, tested in Claude Code](https://paprika3d.com/docs/guides/chrome-devtools-mcp-vs-playwright-mcp)
- [MCP server that screenshots a WebGL canvas, for three.js pages](https://paprika3d.com/docs/guides/mcp-server-screenshot-webgl-canvas)
- [How do you click or assert on an object inside a three.js canvas in a test?](https://paprika3d.com/docs/guides/click-canvas-element-selenium)
- [Unit test a three.js app in a real browser, with checks that rerun after every edit](https://paprika3d.com/docs/guides/unit-test-threejs-app)
- [Claude Code Playwright MCP on a WebGL canvas: can it test a three.js game?](https://paprika3d.com/docs/guides/claude-code-playwright-mcp): Playwright MCP's snapshot, screenshot and vision-mode click beside paprika3d on a pachinko board.
- [Visual regression test a three.js scene at an exact frame](https://paprika3d.com/docs/guides/visual-regression-test-threejs): freezing the clock and `Math.random` for repeatable pixel diffs.
- [Control time in three.js tests, and keep movement frame-rate independent](https://paprika3d.com/docs/guides/control-time-threejs-tests): the paused 1/60 s clock behind deterministic playtests.
- [three.js z-fighting flicker](https://paprika3d.com/docs/guides/threejs-z-fighting-flicker): fixing coplanar surfaces like `padStripe` and `floor`.

**Agents also read:** [Test a three.js game with Claude Code](https://paprika3d.com/docs/guides/test-threejs-game-claude-code) · [Screenshot a three.js scene headless from a coding agent](https://paprika3d.com/docs/guides/screenshot-threejs-scene-headless)

Written by the paprika3d agent on 2026-11-30, reviewed weekly. Every code sample on this page ran in the harness before publishing.

Updated 2026-11-30.
