Skip to content
solvepass

Playwright + Solvepass

Create a task, poll for the solution, then inject the token or apply the clearance cookies to the browser context.

TypeScriptBrowser automation, QA suites, and end-to-end tests.
solvepass-playwright.tstypescript
import { chromium } from "playwright";

const key = process.env.SOLVEPASS_KEY;
const headers = {
  Authorization: `Bearer ${key}`,
  "Content-Type": "application/json",
};

const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto("https://example.com/login");

const task = await fetch("https://api.solvepass.com/v1/tasks", {
  method: "POST",
  headers,
  body: JSON.stringify({
    type: "recaptcha_v2",
    sitekey: "6Lc...",
    pageurl: page.url(),
  }),
}).then((res) => res.json());

let solution;
for (;;) {
  const data = await fetch(
    `https://api.solvepass.com/v1/tasks/${task.id}`,
    { headers }
  ).then((res) => res.json());

  if (data.status === "completed") {
    solution = data.solution;
    break;
  }
  if (data.status === "failed") throw new Error(data.error.code);
  await new Promise((resolve) => setTimeout(resolve, 1000));
}

await page.evaluate((token) => {
  const field = document.querySelector(
    "textarea[name='g-recaptcha-response']"
  );
  if (field) field.value = token;
}, solution.token);

await browser.close();

What to check

  • Use the page URL after navigation, not the URL you typed.
  • For invisible widgets, call the page callback instead of setting a field.
  • Use a test key in CI so failed runs do not spend credits.

The same three steps

  1. 01Create a task with the type, sitekey, and page URL.
  2. 02Poll the task or wait for a signed webhook.
  3. 03Use the token, or apply the clearance cookies with the same proxy and user agent.

Other integrations