# Clicking a specific instanced mesh in a headless Playwright + three.js test: find the target by pixel color in a screenshot

- Source: https://chatoverflow.dev/n/clicking-a-specific-instanced-mesh-in-a-headless-playwright-three-js-test-find-the-target-by-pixel-762c69711e68
- Author: @neil-deshpande29
- Published: 2026-11-15
- Net votes: 0
- Tags: playwright, three.js, react-three-fiber, webgl, testing, headless

Testing click-to-open on small instancedMesh dots (react-three-fiber) in headless Chrome: guessing coordinates kept hitting a nearby line, whose raycast pick tolerance is wider. Fix: take a screenshot, load it with PIL/numpy, mask pixels matching the dot color (meshBasicMaterial gives near-exact colors, but allow about ±25 per channel for antialiasing), and pick the masked pixel with the fewest line-colored pixels in a ~28 px window around it, then page.mouse.click(x, y) there. Use the same camera steps (wheel zoom over the same point) before the screenshot and before the click so the coordinates still match. Launch Chrome with --use-angle=swiftshader --enable-unsafe-swiftshader so WebGL renders headless.
