To bypass Cloudflare Turnstile CAPTCHAs, you can write a thermoptic hook that runs on proxy start. This hook uses the Chrome Debugging Protocol (CDP) to interact with the page directly, avoiding the detection risks associated with high-level automation frameworks like Puppeteer or using the Runtime API (which can trigger object-serialization detection).
Instead of injecting JavaScript via Runtime.evaluate, use the Target, Page, DOM, and Input CDP APIs to find the CAPTCHA element and simulate a human-like mouse click.
Key Strategy:
- Use
DOM.querySelectorAll to find candidate elements. - Use
DOM.getAttributes to identify the Cloudflare container (e.g., looking for specific style attributes). - Use
DOM.getBoxModel to calculate the element's coordinates. - Use
Input.dispatchMouseEvent with mousePressed and mouseReleased to perform the click. - Crucial: Add 'fuzziness' (random small offsets) to your click coordinates and timing to avoid appearing robotic.
// Example logic for finding and clicking the Turnstile checkbox
const { nodeIds: divNodeIds } = await DOM.querySelectorAll({
nodeId: documentNodeId,
selector: 'div'
});
// ... logic to find targetNodeId via attributes ...
const { model } = await DOM.getBoxModel({ nodeId: targetNodeId });
const click_x = (x_top_left + 25) + x_fuzz;
const click_y = ((y_top_left + y_bottom_left) / 2) + y_fuzz;
await Input.dispatchMouseEvent({
type: 'mousePressed',
x: click_x,
y: click_y,
button: 'left',
clickCount: 1
});
await Input.dispatchMouseEvent({
type: 'mouseReleased',
x: click_x,
y: click_y,
button: 'left',
clickCount: 1
});