'How to avoid hcaptcha showing images to solve captcha while using puppeteer for webscraping

I am trying to scrape a site. But, when i try to pass captcha by pressing on captcha checkmark, it gives me the images to solve the captcha. Sometimes it does that and other times it just passes and navigates me to the page after solving captcha.

Below is the code of how I am setting up my puppeteer instance and page.

  puppeteer.use(StealthPlugin());
  
  const chromeOptions = {
    headless: false,
    ignoreHTTPSErrors: true,
    slowMo: 30,
    args: ['--no-sandbox'],
  }

  const browser = await puppeteer.launch(chromeOptions);
  const page = await browser.newPage();
  await page.evaluateOnNewDocument(() => {
    delete navigator.__proto__.webdriver;
  });

  await page.setUserAgent(randomUseragent.getRandom());
  await page.setJavaScriptEnabled(true);
  //page.setDefaultNavigationTimeout(0);
  await page.goto(`pagetoscrape`, {
    waitUntil: "domcontentloaded",
 });

And below is how I am trynna solve captcha.

  await delay(6000);
  const iframes = await page.$('iframe');
  const frame = await iframes.contentFrame();
  const a = await frame.$('#checkbox');
  await a.click();
  await delay(5000);
  await page.screenshot({path: 'headless-test-result.png'});
  console.log("Solving captcha........");
  await page.waitForNavigation();
  await delay(7000);


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source