{
  "name": "hCaptcha with NoneCap (Playwright)",
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ],
      "id": "00000000-0000-4000-8000-000000000001"
    },
    {
      "parameters": {
        "operation": "runCustomScript",
        "scriptCode": "const headless = await $page.evaluate(() => navigator.userAgent);\nconst ua = headless.replace(\"HeadlessChrome\", \"Chrome\");\nconst page = await (await $browser.newContext({ userAgent: ua })).newPage();\nawait page.goto(\"https://target.example/login\");\nconst sitekey = await page.$eval(\"[data-sitekey]\", (el) => el.dataset.sitekey);\nreturn [{ json: { type: \"hcaptcha\", sitekey, url: page.url(), user_agent: ua } }];"
      },
      "name": "Playwright: read sitekey",
      "type": "n8n-nodes-playwright.playwright",
      "typeVersion": 1,
      "position": [
        220,
        0
      ],
      "id": "00000000-0000-4000-8000-000000000002"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.nonecap.com/v1/solves",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "wait",
              "value": "60"
            }
          ]
        },
        "options": {},
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($json) }}"
      },
      "name": "NoneCap: create solve",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        440,
        0
      ],
      "id": "00000000-0000-4000-8000-000000000003"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "still-running",
              "leftValue": "={{ $json.status }}",
              "rightValue": "^(pending|solving)$",
              "operator": {
                "type": "string",
                "operation": "regex"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "name": "Still running?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        660,
        0
      ],
      "id": "00000000-0000-4000-8000-000000000004"
    },
    {
      "parameters": {
        "method": "GET",
        "url": "=https://api.nonecap.com/v1/solves/{{ $json.id }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "wait",
              "value": "60"
            }
          ]
        },
        "options": {}
      },
      "name": "NoneCap: get solve",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        880,
        -200
      ],
      "id": "00000000-0000-4000-8000-000000000005"
    },
    {
      "parameters": {
        "operation": "runCustomScript",
        "scriptCode": "const ua = $(\"Playwright: read sitekey\").first().json.user_agent;\nconst page = await (await $browser.newContext({ userAgent: ua })).newPage();\nif ($json.status !== \"solved\") {\n  throw new Error(`NoneCap solve ${$json.status}: ${$json.error?.message}`);\n}\nawait page.goto($json.url);\nawait page.evaluate((token) => {\n  for (const name of [\"h-captcha-response\", \"g-recaptcha-response\"]) {\n    const el = document.querySelector(`textarea[name=\"${name}\"]`);\n    if (el) el.value = token;\n  }\n}, $json.token);\nawait Promise.all([page.waitForNavigation(), page.click(\"[type=submit]\")]);\nconst text = await page.evaluate(() => document.body.innerText);\nreturn [{ json: { url: page.url(), user_agent: ua, text } }];"
      },
      "name": "Playwright: inject and submit",
      "type": "n8n-nodes-playwright.playwright",
      "typeVersion": 1,
      "position": [
        880,
        0
      ],
      "id": "00000000-0000-4000-8000-000000000006"
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Playwright: read sitekey",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Playwright: read sitekey": {
      "main": [
        [
          {
            "node": "NoneCap: create solve",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "NoneCap: create solve": {
      "main": [
        [
          {
            "node": "Still running?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Still running?": {
      "main": [
        [
          {
            "node": "NoneCap: get solve",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Playwright: inject and submit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "NoneCap: get solve": {
      "main": [
        [
          {
            "node": "Still running?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}
