NEWStandard createTask and in.php APIs. Change the address and you are connected.View API docs
GATESOLVER

AWS WAF and other CAPTCHAs

How to solve the AWS WAF CAPTCHA in Node.js

This guide pairs Playwright with Node's built in fetch: the browser meets the AWS WAF puzzle, the API returns a cookie, and the browser context receives it before the page reloads. Tasks cost $1.40 per 1,000.

Why Playwright and a cookie work well together

The AWS WAF puzzle exists to place a cookie called aws-waf-token in the browser. Once that cookie is in the Playwright browser context, every page and every request in the context carries it, so you solve once and keep browsing. You do not have to click tiles, drag anything or watch the puzzle frame. That makes the approach stable even when the site changes the look of its puzzle.

The plan for this page is short: open the URL, notice the puzzle, read its parameters from the page, solve an AntiAwsWafTaskProxyLess task, add the cookie with context.addCookies(), and reload. If you only need HTML and no JavaScript, the Python requests version is lighter.

Project setup

Use Node.js 18 or newer so fetch and AbortSignal.timeout are built in, then add Playwright. The examples use ES modules, so either name files .mjs or set "type": "module" in package.json.

npm init -y
npm pkg set type=module
npm install playwright
npx playwright install chromium
export GS_TOKEN_KEY=YOUR_API_KEY

A small solver module

Keep the API code in its own file. It exposes one function that takes the page URL and whatever parameters you found, and resolves with the cookie string. Errors are thrown with the API's errorCode so a log line tells you what went wrong without extra digging.

// waf-solver.mjs
const WAF_HOST = 'https://gatesolver.com';
const wafKey = process.env.GS_TOKEN_KEY ?? 'YOUR_API_KEY';
const pause = (ms) => new Promise((done) => setTimeout(done, ms));
const JSON_TYPE = { 'Content-Type': 'application/json' };

async function askGate(method, extra) {
  const res = await fetch(`${WAF_HOST}/${method}`, {
    method: 'POST', body: JSON.stringify({ clientKey: wafKey, ...extra }), headers: JSON_TYPE,
    signal: AbortSignal.timeout(25_000),
  });
  const reply = await res.json();
  if (reply.errorId) throw new Error(`${reply.errorCode}: ${reply.errorDescription ?? ''}`);
  return reply;
}

export async function solveWafCookie(websiteURL, props = {}) {
  const task = { type: 'AntiAwsWafTaskProxyLess', websiteURL };
  if (props.key) task.awsKey = props.key;
  if (props.iv) task.awsIv = props.iv;
  if (props.context) task.awsContext = props.context;
  const { taskId } = await askGate('createTask', { task });
  const stopAt = Date.now() + 125_000;
  while (Date.now() < stopAt) {
    await pause(3000);
    const poll = await askGate('getTaskResult', { taskId });
    if (poll.status === 'ready') return poll.solution.cookie;
    if (poll.status === 'failed') throw new Error(`task ${taskId} failed (not charged)`);
  }
  throw new Error(`task ${taskId} timed out`);
}

Only the fields that have values are copied into the task, which keeps the request clean when the page does not expose all three. The loop waits three seconds before each poll, the interval recommended for token style tasks.

Spot the puzzle inside Playwright

Playwright gives you the main response of every navigation, so the status code is the first clue. At the time of writing the CAPTCHA action answers with 405 and defines window.gokuProps on the page. Reading that object with page.evaluate() is easier than parsing HTML, because the browser has already run the inline script.

// run.mjs
import { chromium, devices } from 'playwright';
import { solveWafCookie } from './waf-solver.mjs';

const target = 'https://example.com/products/search?q=router';
const browser = await chromium.launch({ timeout: 60_000 });
const context = await browser.newContext({ ...devices['Desktop Chrome'] });
const page = await context.newPage();

const first = await page.goto(target, { waitUntil: 'domcontentloaded' });
const goku = await page.evaluate(() => globalThis.gokuProps ?? null);

if (first?.status() === 405 || goku) {
  const cookieValue = await solveWafCookie(target, goku ?? {});
  await context.addCookies([{
    name: 'aws-waf-token', value: cookieValue,
    domain: new URL(target).hostname, path: '/', secure: true,
  }]);
  await page.reload({ waitUntil: 'domcontentloaded' });
}

console.log(await page.title());
await browser.close();

addCookies needs either a url or a domain plus path; the example uses the hostname of the target. If the site serves several subdomains behind the same firewall, check in DevTools which domain the cookie normally carries and use that value.

Detect the check on later pages too

A long crawl can outlive the token. Rather than checking only the first page, wrap navigation in a helper that looks at every main response. When it sees the puzzle again, it solves a fresh task and retries that navigation once.

export async function openGuarded(page, url) {
  let resp = await page.goto(url, { waitUntil: 'domcontentloaded' });
  const props = await page.evaluate(() => globalThis.gokuProps ?? null);
  if (resp?.status() !== 405 && !props) return resp;
  const fresh = await solveWafCookie(url, props ?? {});
  await page.context().addCookies([{ name: 'aws-waf-token', value: fresh, url }]);
  resp = await page.goto(url, { waitUntil: 'domcontentloaded' });
  return resp;
}

This variant passes url instead of domain and path, which is the shorter form Playwright accepts. Both forms produce a cookie scoped to the target host.

Proxies and the browser identity

The proxyless task is the default and works on many sites. Some firewall rules also compare the IP that earned the token with the IP that presents it. If your reload still lands on the puzzle, launch Playwright with a proxy (chromium.launch({ proxy: { server, username, password } })) and send the same proxy in an AntiAwsWafTask with proxy: 'http://user:pass@host:port'. Keep the pair matched for the whole session: a cookie earned through one exit and replayed from another is a common cause of a loop.

Two more habits keep things smooth:

  • Reuse one browser context per site instead of creating a new context per page. The cookie lives in the context, and a new context starts empty.
  • Read the parameters again every time you solve. The context value is single use; an old one leads to a cookie the site will not accept.

Keep the cookie between runs

A scheduled job that starts a fresh browser every hour would solve a new task on every start. Playwright can save the cookies and local storage of a context to a JSON file and load them back later, so a token that is still inside its immunity period is reused instead of paid for again.

import { existsSync } from 'node:fs';

const statePath = './waf-state.json';
const savedCtx = await browser.newContext(
  existsSync(statePath) ? { storageState: statePath } : {},
);
// ... browse with openGuarded(page, url) ...
await savedCtx.storageState({ path: statePath });

On the next run the first navigation either passes straight through or shows the puzzle again, and openGuarded handles both cases without extra code. Keep the state file private: it holds live session cookies for the site, so treat it like a password file and keep it out of version control.

When the reload still shows the puzzle

SymptomLikely cause and fix
gokuProps is null but status is 405The page uses a different integration script. Solve with websiteURL only; the optional fields can be left out.
Puzzle returns after reloadIP mismatch. Use AntiAwsWafTask with the same proxy as the browser.
ERROR_INVALID_TASK_DATAThe description names the field; usually websiteURL was empty or not absolute.
Cookie works, then stopsThe immunity period ended. Let openGuarded solve again.

The Playwright integration guide shows the same pattern for other CAPTCHA types, and the Playwright glossary entry explains contexts if you are new to them.

Use this for monitoring catalogs, checking your own deployments behind AWS WAF, or collecting public listings. One cookie per session keeps both cost and load on the site low.

Common questions

Can I use Puppeteer instead of Playwright here?

Yes. Read gokuProps the same way with page.evaluate and set the cookie with page.setCookie before reloading; the API part does not change.

Why read gokuProps with page.evaluate instead of a regex?

The browser has already run the inline script, so the object is ready to read and you avoid parsing fragile HTML.

Does the cookie need the secure flag?

Sites served over HTTPS normally expect it. Setting secure: true matches what a real browser stores for an https page.

Is there an npm package for GateSolver?

No package is needed. The API is two JSON endpoints, and the small module on this page covers them with the built in fetch.

How many pages can one cookie cover?

Every request in the same browser context until the site's immunity period ends, so a single solve usually covers many pages.

Keep reading