Automating Captchas with Playwright & Death By Captcha

You are here:-, Usage best practices-Automating Captchas with Playwright & Death By Captcha

Automating Captchas with Playwright & Death By Captcha

Browser automation becomes significantly more powerful when combined with intelligent captcha solving. If your workflow involves solving a captcha and submitting it to a website, manually solving it quickly becomes inefficient. A more scalable approach is to combine our captcha solving API with Playwright. This article walks through how to implement that workflow using Node.js.


The workflow in a nutshell

The first step is submitting the captcha to Death By Captcha API, check if the token is ready by polling the API every 5 seconds until a token is returned, then the token is inserted into the hidden textarea element with ID g-recaptcha-response and finally the form needs to be submitted.

This is a high level view of the whole pipeline:


Why Use Playwright for This Workflow?

There are several browser automation frameworks available, but Playwright is especially well suited for modern API-driven automation.

a) Built-in async/await support

The workflow reads clearly from top to bottom.

This makes automation scripts easier to maintain.

b) Cleaner browser interaction

Playwright provides direct methods for common form interactions such as:

  • Filling fields
  • Clicking buttons
  • Waiting for page readiness

This keeps your implementation concise.


Understanding how to set up your own Playwright automation

Note: We have added the full code at the bottom, this section is a high level overview of the overall Playwright workflow.

Stage 1: Configure client to solve the captcha

a) Either Integrate our existing Node.js client with your own logic,

b) or use the sample code at the bottom section of the article (you can read more about it’s internal functions and setup).

Stage 2: Install required dependencies
Copy to Clipboard

The npm dependency gives your Node.js application access to browser automation.

The npx dependency is needed since it gives you the binaries, downloads the actual browsers Playwright controls:

  • Chromium
  • Firefox
  • WebKit
Stage 3: Configuring the Submission Target

The first part of the implementation defines the destination and selectors.

And the page elements:

Centralizing selectors makes updates easier if the page structure changes.

Stage 4: Get the Captcha Result

Before interacting with the browser, your application needs to confirm that Death By Captcha API returned a token.

Its job is to:

  • Return the token fetched
  • Close the app on error

This prevents invalid submissions.

Stage 5: Launch Chromium

Playwright launches Chromium (This creates a browser context ready for automation) and calls `submitToPage()` which receives Playwright context and which executes the submission to the page only if a token was successfully fetched.

Stage 6: Submission of token & form

The final step:

submitToPage()

  1. Waits until Playwright goes to the submission URL
  2. To then Wait for the text area and token injection
  3. Waits until form gets submitted with a click on the submit button.

This completes the workflow automatically.


Complete code:


Step 1: Make sure your ‘package.json’ is set up correctly

Make sure:

  • That “type” is set to “module” for ES6.
  • To have index.js as your app entry point by setting “main”: “index.js”
  • Have a “start” script which runs your Node.js app; “start”: “node index.js”.

Step 2: Install dependencies

Skip this step if you’ve already installed them in the previous section

Copy to Clipboard

Step 3: Use the code

Copy to Clipboard
Copy to Clipboard

Expected output:

By |2026-05-26T21:59:15+00:00May 26th, 2026|Categories: Usage, Usage best practices|Comments Off on Automating Captchas with Playwright & Death By Captcha