{"version":3,"sources":["jsdelivr-header.js","/npm/@extra/humanize@4.2.1-next.613/src/mouse/math.ts","/npm/@extra/humanize@4.2.1-next.613/src/mouse/calc.ts","/npm/@extra/humanize@4.2.1-next.613/src/mouse/spoof.ts","/npm/@extra/humanize@4.2.1-next.613/src/mouse/helper.ts","/npm/@extra/humanize@4.2.1-next.613/src/index.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;iICJA,MAAM,OAAS,QAAQ,aAMV,OAAiB,CAAE,EAAG,EAAG,EAAG,GAG5B,IAAM,CAAC,EAAW,KAAS,CACtC,EAAG,EAAE,EAAI,EAAE,EACX,EAAG,EAAE,EAAI,EAAE,IAEA,IAAM,CAAC,EAAW,KAAS,CACtC,EAAG,EAAE,EAAI,EACT,EAAG,EAAE,EAAI,IAEE,KAAO,CAAC,EAAW,KAAS,CACvC,EAAG,EAAE,EAAI,EACT,EAAG,EAAE,EAAI,IAEE,IAAM,CAAC,EAAW,KAAS,CACtC,EAAG,EAAE,EAAI,EAAE,EACX,EAAG,EAAE,EAAI,EAAE,IAGA,UAAY,CAAC,EAAW,IAAsB,IAAI,EAAG,GACrD,cAAiB,IAAS,CAAgB,EAAG,EAAE,EAAG,GAAI,EAAI,EAAE,IAC5D,UAAa,GACxB,KAAK,KAAK,KAAK,IAAI,EAAE,EAAG,GAAK,KAAK,IAAI,EAAE,EAAG,IAChC,KAAQ,GAAsB,IAAI,EAAG,UAAU,IAC/C,aAAe,CAAC,EAAW,IACtC,KAAK,KAAK,GAAI,GAKH,mBAAqB,CAAC,EAAW,KAC5C,MAAM,EAAM,UAAU,EAAG,GACnB,EAAa,KAAK,SACxB,OAAO,IAAI,EAAG,KAAK,EAAK,GAAY,EAGhC,iBAAmB,CACvB,EACA,EACA,KAEA,MAAM,EAAU,mBAAmB,EAAG,GAEtC,MAAO,CAAC,EADQ,aAAa,cAAc,UAAU,EAAG,IAAW,GAC1C,EAGd,sBAAwB,CACnC,EACA,EACA,KAE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ACA,IACE,EAAc,EAAM,SACpB,EAAI,UAAU,IAAI,uBAAuB,IAE3C,GAEF,SAAS,iBACP,cACA,IACE,EAAc,EAAM,SACpB,EAAI,UAAU,OAAO,uBAAuB,IAE9C,E,IAUJ,EACD,EAGU,cAAgB,MAAO,EAAY,KAC9C,GAAI,EAAI,gBAAgB,GACtB,aAAa,EAAK,sBAAsB,eAE1C,GAAI,EAAI,iBAAiB,GACvB,aAAa,EAAK,cAAc,eAElC,MAAM,IAAI,MAAM,qBAAqB,E,MC/F1B,uBAAuB,4CAClC,WAAA,CAAY,EAAoC,IAC9C,MAAM,E,CAGR,aAAW,GACT,MAAO,U,CAGT,YAAI,GACF,MAAO,CACL,MAAO,CACL,SAAS,EACT,YAAY,G,CAMX,MAAA,GACL,KAAK,KAAK,MAAM,SAAU,C,CAIrB,OAAA,GACL,KAAK,KAAK,MAAM,SAAU,C,CAG5B,mBAAM,CAAc,GAElB,GADA,KAAK,MAAM,gBAAiB,KAAK,OACD,IAA5B,KAAK,KAAK,MAAM,QAClB,QAGiC,IAA/B,KAAK,KAAK,MAAM,YAElB,cAA0B,EAAM,KAAK,KAGvC,MAAM,EAAS,aAAmB,GAGlC,EAAK,MAAQ,EAAE,EAAgB,IACtB,MACL,EACA,KAEA,IAAgC,IAA5B,KAAK,KAAK,MAAM,QAClB,aAAa,EAAe,MAAM,EAAK,CAAC,EAAU,IAGpD,IAEE,aAAa,EAAO,MAAM,E,CAC1B,MAAO,GAMP,OALA,QAAQ,KACN,iCAAiC,MACjC,EAAI,YAEN,QAAQ,IAAI,kDACC,EAAe,MAAM,EAAK,CAAC,EAAU,G,GAlB3C,CAqBV,EAAK,MAAO,E,EAKnB,MAAM,cAAiB,GACd,IAAI,eAAe,G","file":"/npm/@extra/humanize@4.2.1-next.613/dist/index.cjs.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@extra/humanize@4.2.1-next.613/dist/index.cjs.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","// Taken from: https://github.com/Xetera/ghost-cursor/blob/master/src/math.ts\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst Bezier = require('bezier-js') as typeof BezierJs.Bezier\n\nexport interface Vector {\n  x: number\n  y: number\n}\nexport const origin: Vector = { x: 0, y: 0 }\n\n// maybe i should've just imported a vector library lol\nexport const sub = (a: Vector, b: Vector): Vector => ({\n  x: a.x - b.x,\n  y: a.y - b.y\n})\nexport const div = (a: Vector, b: number): Vector => ({\n  x: a.x / b,\n  y: a.y / b\n})\nexport const mult = (a: Vector, b: number): Vector => ({\n  x: a.x * b,\n  y: a.y * b\n})\nexport const add = (a: Vector, b: Vector): Vector => ({\n  x: a.x + b.x,\n  y: a.y + b.y\n})\n\nexport const direction = (a: Vector, b: Vector): Vector => sub(b, a)\nexport const perpendicular = (a: Vector): Vector => ({ x: a.y, y: -1 * a.x })\nexport const magnitude = (a: Vector): number =>\n  Math.sqrt(Math.pow(a.x, 2) + Math.pow(a.y, 2))\nexport const unit = (a: Vector): Vector => div(a, magnitude(a))\nexport const setMagnitude = (a: Vector, amount: number): Vector =>\n  mult(unit(a), amount)\n\nexport const randomNumberRange = (min: number, max: number): number =>\n  Math.random() * (max - min) + min\n\nexport const randomVectorOnLine = (a: Vector, b: Vector): Vector => {\n  const vec = direction(a, b)\n  const multiplier = Math.random()\n  return add(a, mult(vec, multiplier))\n}\n\nconst randomNormalLine = (\n  a: Vector,\n  b: Vector,\n  range: number\n): [Vector, Vector] => {\n  const randMid = randomVectorOnLine(a, b)\n  const normalV = setMagnitude(perpendicular(direction(a, randMid)), range)\n  return [randMid, normalV]\n}\n\nexport const generateBezierAnchors = (\n  a: Vector,\n  b: Vector,\n  spread: number\n): [Vector, Vector] => {\n  const side = Math.round(Math.random()) === 1 ? 1 : -1\n  const calc = (): Vector => {\n    const [randMid, normalV] = randomNormalLine(a, b, spread)\n    const choice = mult(normalV, side)\n    return randomVectorOnLine(randMid, add(randMid, choice))\n  }\n  return [calc(), calc()].sort((a, b) => a.x - b.x) as [Vector, Vector]\n}\n\nconst clamp = (target: number, min: number, max: number): number =>\n  Math.min(max, Math.max(min, target))\n\nexport const overshoot = (coordinate: Vector, radius: number): Vector => {\n  const a = Math.random() * 2 * Math.PI\n  const rad = radius * Math.sqrt(Math.random())\n  const vector = { x: rad * Math.cos(a), y: rad * Math.sin(a) }\n  return add(coordinate, vector)\n}\n\nexport const bezierCurve = (\n  start: Vector,\n  finish: Vector,\n  overrideSpread?: number\n): BezierJs.Bezier => {\n  // could be played around with\n  const min = 2\n  const max = 200\n  const vec = direction(start, finish)\n  const length = magnitude(vec)\n  const spread = clamp(length, min, max)\n  const anchors = generateBezierAnchors(start, finish, overrideSpread ?? spread)\n  return new Bezier(start, ...anchors, finish)\n}\n","import { Vector, bezierCurve } from './math'\n\nimport type { Box } from './types'\n\n/**\n * Calculate the amount of time needed to move from (x1, y1) to (x2, y2)\n * given the width of the element being clicked on\n * https://en.wikipedia.org/wiki/Fitts%27s_law\n */\nconst fitts = (distance: number, width: number): number => {\n  const a = 0\n  const b = 2\n  const id = Math.log2(distance / width + 1)\n  return a + b * id\n}\n\nconst isBox = (a: any): a is Box => 'width' in a\n\nexport function path(\n  point: Vector,\n  target: Vector,\n  spreadOverride?: number\n): Vector[]\nexport function path(\n  point: Vector,\n  target: Box,\n  spreadOverride?: number\n): Vector[]\nexport function path(\n  start: Vector,\n  end: Box | Vector,\n  spreadOverride?: number\n): Vector[] {\n  const defaultWidth = 100\n  const minSteps = 25\n  const width = isBox(end) ? end.width : defaultWidth\n  const curve = bezierCurve(start, end, spreadOverride)\n  const length = curve.length() * 0.8\n  const baseTime = Math.random() * minSteps\n  const steps = Math.ceil((Math.log2(fitts(length, width) + 1) + baseTime) * 3)\n  const re = curve.getLUT(steps)\n  return clampPositive(re)\n}\n\nconst clampPositive = (vectors: Vector[]): Vector[] => {\n  const clamp0 = (elem: number): number => Math.max(0, elem)\n  return vectors.map(vector => {\n    return {\n      x: clamp0(vector.x),\n      y: clamp0(vector.y)\n    }\n  })\n}\n","// Heavily based on: https://github.com/Xetera/ghost-cursor/blob/master/src/spoof.ts\nimport { Vector, direction, magnitude, origin, overshoot } from './math'\nimport * as calc from './calc'\n\nimport type { Puppeteer, Playwright } from 'automation-extra-plugin'\nimport type { Box } from './types'\n\ntype Page = Puppeteer.Page | Playwright.Page\ntype ElementHandle = Puppeteer.ElementHandle | Playwright.ElementHandle\n\n/**\n * Type guard, will make TypeScript understand which type we're working with.\n */\nfunction isPlaywrightPage(obj: any): obj is Playwright.Page {\n  return 'unroute' in (obj as Playwright.Page)\n}\n\n/**\n * Type guard, will make TypeScript understand which type we're working with.\n */\nfunction isPlaywrightElementHandle(obj: any): obj is Playwright.ElementHandle {\n  return !('$x' in (obj as Playwright.ElementHandle))\n}\n\ninterface BoxOptions {\n  readonly paddingPercentage: number\n}\ninterface MoveOptions extends BoxOptions {\n  readonly waitForSelector: number\n}\ninterface ClickOptions extends MoveOptions {\n  readonly waitForClick: number\n}\n\n// Helper function to wait a specified number of milliseconds\nconst delay = async (ms: number): Promise<void> =>\n  await new Promise(resolve => setTimeout(resolve, ms))\n\n// Get a random point on a box\nconst getRandomBoxPoint = (\n  { x, y, width, height }: Box,\n  options?: BoxOptions\n): Vector => {\n  let paddingWidth = 0\n  let paddingHeight = 0\n\n  if (\n    options?.paddingPercentage !== undefined &&\n    options?.paddingPercentage > 0 &&\n    options?.paddingPercentage < 100\n  ) {\n    paddingWidth = (width * options.paddingPercentage) / 100\n    paddingHeight = (height * options.paddingPercentage) / 100\n  }\n\n  return {\n    x: x + paddingWidth / 2 + Math.random() * (width - paddingWidth),\n    y: y + paddingHeight / 2 + Math.random() * (height - paddingHeight)\n  }\n}\n\n// Get a random point on a browser window\n// export const getRandomPagePoint = async (page: Page): Promise<Vector> => {\n//   const targetId: string = (page.target() as any)._targetId\n//   const window = await (page as any)._client.send(\n//     'Browser.getWindowForTarget',\n//     { targetId }\n//   )\n//   return getRandomBoxPoint({\n//     x: origin.x,\n//     y: origin.y,\n//     width: window.bounds.width,\n//     height: window.bounds.height\n//   })\n// }\n\n// Using this method to get correct position of Inline elements (elements like <a>)\nconst getElementBox = async (\n  page: Page,\n  element: ElementHandle,\n  relativeToMainFrame: boolean = true\n): Promise<Box | null> => {\n  if (isPlaywrightPage(page)) {\n    // TODO: Check if in main frame\n    return await element.boundingBox()\n  }\n\n  if (\n    (element as any)._remoteObject === undefined ||\n    (element as any)._remoteObject.objectId === undefined\n  ) {\n    // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n    return null\n  }\n  const quads = await (page as any)._client.send('DOM.getContentQuads', {\n    // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n    objectId: (element as any)._remoteObject.objectId\n  })\n  const elementBox = {\n    x: quads.quads[0][0],\n    y: quads.quads[0][1],\n    width: quads.quads[0][4] - quads.quads[0][0],\n    height: quads.quads[0][5] - quads.quads[0][1]\n  }\n  if (elementBox === null) {\n    return null\n  }\n  if (!relativeToMainFrame) {\n    const elementFrame = ((element as Puppeteer.ElementHandle).executionContext() as any).frame()\n    const iframes = await elementFrame.parentFrame().$x('//iframe')\n    let frame = null\n    for (const iframe of iframes) {\n      if ((await iframe.contentFrame()) === elementFrame) frame = iframe\n    }\n    if (frame !== null) {\n      const boundingBox = await (frame as ElementHandle).boundingBox()\n      elementBox.x =\n        boundingBox !== null ? elementBox.x - boundingBox.x : elementBox.x\n      elementBox.y =\n        boundingBox !== null ? elementBox.y - boundingBox.y : elementBox.y\n    }\n  }\n  return elementBox\n}\n\nconst overshootThreshold = 500\nconst shouldOvershoot = (a: Vector, b: Vector): boolean =>\n  magnitude(direction(a, b)) > overshootThreshold\n\nexport const createCursor = (\n  page: Page,\n  start: Vector = origin,\n  performRandomMoves: boolean = false\n) => {\n  // this is kind of arbitrary, not a big fan but it seems to work\n  const overshootSpread = 10\n  const overshootRadius = 120\n  let previous: Vector = start\n\n  // Initial state: mouse is not moving\n  let moving: boolean = false\n\n  // Move the mouse over a number of vectors\n  const tracePath = async (\n    vectors: Iterable<Vector>,\n    abortOnMove: boolean = false\n  ): Promise<void> => {\n    for (const v of vectors) {\n      try {\n        // In case this is called from random mouse movements and the users wants to move the mouse, abort\n        if (abortOnMove && moving) {\n          return\n        }\n        await page.mouse.move(v.x, v.y)\n        previous = v\n      } catch (error) {\n        // Exit function if the browser is no longer connected\n        const isConnected = isPlaywrightPage(page)\n          ? page.context().browser()?.isConnected\n          : page.browser().isConnected()\n        // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n        if (!isConnected) return\n\n        console.log('Warning: could not move mouse, error message:', error)\n      }\n    }\n  }\n\n  // Start random mouse movements. Function recursively calls itself\n  // const randomMove = async (): Promise<void> => {\n  //   try {\n  //     if (!moving) {\n  //       const rand = await getRandomPagePoint(page)\n  //       await tracePath(path(previous, rand), true)\n  //       previous = rand\n  //     }\n  //     await delay(Math.random() * 2000) // wait max 2 seconds\n  //     randomMove().then(\n  //       _ => {},\n  //       _ => {}\n  //     ) // fire and forget, recursive function\n  //   } catch (_) {\n  //     console.log('Warning: stopping random mouse movements')\n  //   }\n  // }\n\n  const actions = {\n    toggleRandomMove(random: boolean): void {\n      moving = !random\n    },\n\n    async click(\n      selector?: string | ElementHandle,\n      options?: ClickOptions\n    ): Promise<void> {\n      actions.toggleRandomMove(false)\n\n      if (selector !== undefined) {\n        await actions.move(selector, options)\n        actions.toggleRandomMove(false)\n      }\n\n      try {\n        await page.mouse.down()\n        if (options?.waitForClick !== undefined) {\n          await delay(options.waitForClick)\n        }\n        await page.mouse.up()\n      } catch (error) {\n        console.log('Warning: could not click mouse, error message:', error)\n      }\n\n      await delay(Math.random() * 2000)\n      actions.toggleRandomMove(true)\n    },\n    async move(selector: string | ElementHandle, options?: MoveOptions) {\n      actions.toggleRandomMove(false)\n      let elem: ElementHandle | null = null\n      if (typeof selector === 'string') {\n        if (selector.includes('//')) {\n          if (options?.waitForSelector !== undefined) {\n            // TODO: Refactor and make Playwright compatible\n            // @see xpath: https://stackoverflow.com/a/59924073\n            // await page.waitForXPath(selector, {\n            //   timeout: options.waitForSelector\n            // })\n          }\n          // elem = await page.$x(selector)\n        } else {\n          if (options?.waitForSelector !== undefined) {\n            // await page.waitForSelector(selector, {\n            //   timeout: options.waitForSelector\n            // })\n          }\n          elem = await page.$(selector)\n        }\n        if (elem === null) {\n          throw new Error(\n            `Could not find element with selector \"${selector}\", make sure you're waiting for the elements with \"puppeteer.waitForSelector\"`\n          )\n        }\n      } else {\n        elem = selector\n      }\n\n      // Make sure the object is in view\n      if (isPlaywrightElementHandle(elem)) {\n        await elem.scrollIntoViewIfNeeded()\n      } else {\n        // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n        if (\n          (elem as any)._remoteObject !== undefined &&\n          (elem as any)._remoteObject.objectId !== undefined\n        ) {\n          await (page as any)._client.send('DOM.scrollIntoViewIfNeeded', {\n            // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n            objectId: (elem as any)._remoteObject.objectId\n          })\n        }\n      }\n\n      const box = await getElementBox(page, elem)\n      if (box === null) {\n        throw new Error(\n          \"Could not find the dimensions of the element you're clicking on, this might be a bug?\"\n        )\n      }\n      const { height, width } = box\n      const destination = getRandomBoxPoint(box, options)\n      const dimensions = { height, width }\n      const overshooting = shouldOvershoot(previous, destination)\n      const to = overshooting\n        ? overshoot(destination, overshootRadius)\n        : destination\n      await tracePath(calc.path(previous, to))\n\n      if (overshooting) {\n        const correction = calc.path(\n          to,\n          { ...dimensions, ...destination },\n          overshootSpread\n        )\n\n        await tracePath(correction)\n      }\n      previous = destination\n\n      actions.toggleRandomMove(true)\n    },\n    async moveTo(destination: Vector) {\n      actions.toggleRandomMove(false)\n      await tracePath(calc.path(previous, destination))\n      actions.toggleRandomMove(true)\n    }\n  }\n\n  // Start random mouse movements. Do not await the promise but return immediately\n  // if (performRandomMoves)\n  // TODO: Fix random move thing\n  // randomMove().then(\n  //   _ => {},\n  //   _ => {}\n  // )\n\n  return actions\n}\n","// Heavily based on: https://github.com/Xetera/ghost-cursor/\nimport type { Page, LauncherEnv } from 'automation-extra-plugin'\n\nconst contentScript = () => {\n  window.addEventListener(\n    'DOMContentLoaded',\n    () => {\n      const box = document.createElement('p-mouse-pointer')\n      const styleElement = document.createElement('style')\n      styleElement.innerHTML = `\n        p-mouse-pointer {\n          pointer-events: none;\n          position: absolute;\n          top: 0;\n          z-index: 10000;\n          left: 0;\n          width: 20px;\n          height: 20px;\n          background: rgba(0,0,0,.4);\n          border: 1px solid white;\n          border-radius: 10px;\n          margin: -10px 0 0 -10px;\n          padding: 0;\n          transition: background .2s, border-radius .2s, border-color .2s;\n        }\n        p-mouse-pointer.button-1 {\n          transition: none;\n          background: rgba(0,0,0,0.9);\n        }\n        p-mouse-pointer.button-2 {\n          transition: none;\n          border-color: rgba(0,0,255,0.9);\n        }\n        p-mouse-pointer.button-3 {\n          transition: none;\n          border-radius: 4px;\n        }\n        p-mouse-pointer.button-4 {\n          transition: none;\n          border-color: rgba(255,0,0,0.9);\n        }\n        p-mouse-pointer.button-5 {\n          transition: none;\n          border-color: rgba(0,255,0,0.9);\n        }\n        p-mouse-pointer-hide {\n          display: none\n        }\n      `\n      document.head.appendChild(styleElement)\n      document.body.appendChild(box)\n      document.addEventListener(\n        'mousemove',\n        event => {\n          box.style.left = String(event.pageX) + 'px'\n          box.style.top = String(event.pageY) + 'px'\n          box.classList.remove('p-mouse-pointer-hide')\n          updateButtons(event.buttons)\n        },\n        true\n      )\n      document.addEventListener(\n        'mousedown',\n        event => {\n          updateButtons(event.buttons)\n          box.classList.add('button-' + String(event.which))\n          box.classList.remove('p-mouse-pointer-hide')\n        },\n        true\n      )\n      document.addEventListener(\n        'mouseup',\n        event => {\n          updateButtons(event.buttons)\n          box.classList.remove('button-' + String(event.which))\n          box.classList.remove('p-mouse-pointer-hide')\n        },\n        true\n      )\n      document.addEventListener(\n        'mouseleave',\n        event => {\n          updateButtons(event.buttons)\n          box.classList.add('p-mouse-pointer-hide')\n        },\n        true\n      )\n      document.addEventListener(\n        'mouseenter',\n        event => {\n          updateButtons(event.buttons)\n          box.classList.remove('p-mouse-pointer-hide')\n        },\n        true\n      )\n      /* eslint-disable */\n      function updateButtons(buttons: any) {\n        for (let i = 0; i < 5; i++) {\n          // @ts-ignore\n          box.classList.toggle('button-' + String(i), buttons & (1 << i))\n        }\n      }\n    },\n    false\n  )\n}\n\nexport const installHelper = async (page: Page, env: LauncherEnv) => {\n  if (env.isPuppeteerPage(page)) {\n    return await page.evaluateOnNewDocument(contentScript)\n  }\n  if (env.isPlaywrightPage(page)) {\n    return await page.addInitScript(contentScript)\n  }\n  throw new Error('Unsupported driver')\n}\n","import { AutomationExtraPlugin, Playwright } from 'automation-extra-plugin'\nimport * as mouse from './mouse/spoof'\nimport * as mouseHelper from './mouse/helper'\n\nimport type { Puppeteer, Page } from 'automation-extra-plugin'\n\ntype PlaywrightClickOptions = Parameters<Playwright.Page['click']>\n\nexport interface MouseOpts {\n  /** Enable human mouse movements when clicking */\n  enabled: boolean\n  /** Show a visible cursor (for testing, not for production) */\n  showCursor: boolean\n}\n\nexport interface HumanizePluginOpts {\n  mouse: Partial<MouseOpts>\n}\n\nexport class HumanizePlugin extends AutomationExtraPlugin<HumanizePluginOpts> {\n  constructor(opts: Partial<HumanizePluginOpts> = {}) {\n    super(opts)\n  }\n\n  static get id() {\n    return 'humanize'\n  }\n\n  get defaults() {\n    return {\n      mouse: {\n        enabled: true,\n        showCursor: false\n      }\n    }\n  }\n\n  /** Enable the humanize plugin */\n  public enable() {\n    this.opts.mouse.enabled = true\n  }\n\n  /** Disable the humanize plugin */\n  public disable() {\n    this.opts.mouse.enabled = false\n  }\n\n  async onPageCreated(page: Page) {\n    this.debug('onPageCreated', this.opts)\n    if (this.opts.mouse.enabled === false) {\n      return\n    }\n\n    if (this.opts.mouse.showCursor === true) {\n      // eslint-disable-next-line @typescript-eslint/no-floating-promises\n      mouseHelper.installHelper(page, this.env)\n    }\n\n    const cursor = mouse.createCursor(page)\n\n    // TODO: Support elementHandle.click\n    page.click = ((originalMethod, ctx) => {\n      return async (\n        selector: string,\n        options?: Puppeteer.ClickOptions | PlaywrightClickOptions | undefined\n      ) => {\n        if (this.opts.mouse.enabled === false) {\n          return await originalMethod.apply(ctx, [selector, options as any])\n        }\n\n        try {\n          // TODO: Imitate regular page.click options (delay, etc)\n          return await cursor.click(selector)\n        } catch (err) {\n          console.warn(\n            `An error occured clicking on \"${selector}\":`,\n            err.toString()\n          )\n          console.log('Skipping humanize and use vanilla click.')\n          return await originalMethod.apply(ctx, [selector, options as any])\n        }\n      }\n    })(page.click, page)\n  }\n}\n\n/** Default export  */\nconst defaultExport = (opts?: Partial<HumanizePluginOpts>) => {\n  return new HumanizePlugin(opts)\n}\n\nexport default defaultExport\n"]}