From 5e340f33e68649608b6015290b33b32c1078fad5 Mon Sep 17 00:00:00 2001 From: alperensert <63921520+alperensert@users.noreply.github.com> Date: Sun, 28 Apr 2024 14:24:30 +0300 Subject: [PATCH] feat: added data dome task class for handling Data Dome captchas --- src/index.ts | 1 + src/tasks/data_dome.ts | 105 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 src/tasks/data_dome.ts diff --git a/src/index.ts b/src/index.ts index d2fc85b..24e2c42 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ export { CapmonsterError } from "./capmonster_error" export { AmazonTask } from "./tasks/aws_waf" export { ComplexImageTask } from "./tasks/complex_image" +export { DataDomeTask } from "./tasks/data_dome" export { FuncaptchaTask } from "./tasks/fun_captcha" export { GeeTestTask } from "./tasks/geetest" export { GeeTestV4Task } from "./tasks/geetest_v4" diff --git a/src/tasks/data_dome.ts b/src/tasks/data_dome.ts new file mode 100644 index 0000000..4bca71f --- /dev/null +++ b/src/tasks/data_dome.ts @@ -0,0 +1,105 @@ +import { ITask, ITaskSolution, UAProxy } from "../capmonster" + +/** + * DataDomeTask class for handling data dome captchas + * @since v0.4.5 + */ +export class DataDomeTask extends UAProxy { + /** + * Initialize a new DataDomeTask for handling the captchas + * @param clientKey Unique key of your account + */ + constructor(clientKey: string) { + super(clientKey) + } + + /** + * Creates only the task configuration for reuseable tasks. + * @param task {@link IDataDomeTaskRequest} + * @returns Only the task you created {@link IDataDomeTaskRequest} + */ + public task = (task: Omit) => task + + /** + * Creates a data dome captcha task for solving + * @param task {@link task} + * @returns ID of the created task + * @since v0.4.4 + */ + public createWithTask = async ( + task: Omit + ): Promise => { + const data: IDataDomeTaskRequest = { + type: "CustomTask", + class: "DataDome", + ...task, + } + const [userAgentData] = this.isUserAgentTask(data) + return await this._createTask(userAgentData) + } + + /** + * Get task result + * @param taskId Task id which returns from {@link createWithTask} function. + * @returns Returns the solution if captcha is solved, otherwise null + * @also see {@link joinTaskResult} + */ + public getTaskResult = async (taskId: number) => + this._getTaskResult(taskId) + + /** + * Get task result. This function is waits until task to be solved. + * @param taskId Task id which returns from {@link createWithTask} function. + * @param timeout (as seconds) Sets the timeout for the current execution of this function. + * @returns Solution of the task + * @throws CapmonsterError, if task can't be solved in maximum time + * @also see {@link getTaskResult} + */ + public joinTaskResult = async (taskId: number, timeout?: number) => + this._joinTaskResult(taskId, timeout) +} + +interface IDataDomeTaskRequestMetaData { + /** + * Object that contains additional data about the captcha: "htmlPageBase64": "..." - + * a base64 encoded html page that comes with a 403 code and a Set-Cookie: datadome="..." + * header in response to a get request to the target site. + */ + htmlPageBase64: string + /** + * Link to the captcha. + * @example "https://geo.captcha-delivery.com/captcha/?initialCid=..." + */ + captchaUrl: string + /** + * Your cookies from datadome. + * + * You can get the cookies on the captcha page using "document.cookie" or + * in the Set-Cookie request header: "datadome=..." + */ + datadomeCookie: string +} + +interface IDataDomeTaskRequest extends ITask { + type: "CustomTask" + class: "DataDome" + /** + * Address of the main page where the captcha is solved. + */ + websiteURL: string + /** + * @see {@link IDataDomeTaskRequestMetaData} + */ + metadata: IDataDomeTaskRequestMetaData +} + +interface IDataDomeTaskResponse extends ITaskSolution { + /** + * @example "site.com": { + * "cookies": { + * "datadome": "t355hfeuUFbsWpoMzXyIWL_ewfwgre25345323rwgregeFEkG5iju9esKVfWMzuLAjcfCIJUIHU7332At1l~HY78g782hidwfeO4K2ZP_CFHYUFEgygfiYGfGYEUfgyefWrXG6_3sy; Max-Age=31536000; Domain=.site.com; Path=/; Secure; SameSite=Lax" + * } + * } + */ + domains: Record +}