Skip to content

Puppeteer

Puppeteer’s page.evaluate(fn, arg) runs the helper module’s page functions; solveOnPage chains finding, solving and putting the token back.

Terminal window
npm install puppeteer
export NOPTCHA_KEY=nop_test_... # a test key: free, fixed answers
# no account yet? export NOPTCHA_KEY=keyless (keyless sandbox, same fixed answers)

Save noptcha-browser.mjs next to your script (Node.js 22 or later, ES modules).

signup.mjs
import puppeteer from 'puppeteer';
import { solveOnPage } from './noptcha-browser.mjs';
const URL = 'https://example.com/signup'; // a page you are allowed to automate
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(URL, { waitUntil: 'load' });
// ... fill in the form as usual ...
// find the captcha, solve it, put the token back (page.evaluate runs the helper's functions in the page)
const result = await solveOnPage((fn, arg) => page.evaluate(fn, arg));
if (result) console.log('solved', result.type, '->', result.did);
await Promise.all([page.waitForNavigation(), page.click('button[type=submit]')]); // your page's submit button
console.log(page.url(), await page.title());
await browser.close();

solveOnPage returns null when the page shows no captcha the helper recognizes, else { type, params, solution, did }, where did lists the fields it filled and the callbacks it called. To do the steps yourself: const [captcha] = await page.evaluate(findCaptchas), then solve(captcha.type, captcha.params), then page.evaluate(putToken, { type: captcha.type, token: solution.token }).

  • Timing. Find the captcha once the widget is on the page and solve right before you submit: tokens expire after a couple of minutes.
  • Frames. For a widget inside an iframe, use that frame’s evaluate (page.frames()) instead of the page’s.
  • puppeteer-core. With puppeteer-core and your own Chrome (puppeteer.launch({ executablePath }) or puppeteer.connect(...)) the code is the same.