I'm using puppeteer and https://www.deathbycaptcha.com/ to automatically solve a captcha.
Here is my function to solve the captcha.
async function solve_captcha(page, client, captcha_selector, imgName) {
  console.log("0")
  const attr = await page.$$eval(captcha_selector, el => el.map(x => x.getAttribute("style")));
  console.log("1")
  const captchaUrl = attr[0].match(/(?<=url\(')(.*)(?='\))/g)[0];
  console.log("2")
  await base64ImageDecoder.convert(captchaUrl, './', imgName).then(result => {console.log(result);}).catch(err => console.error(err));
  console.log("3")
  const captcha_file = imgName+'.jpg';
  console.log("4" + captcha_file)
  await client.get_balance((balance) => {
    console.log(balance);
  });
  let captchaText = "abc";
  await client.decode({captcha: captcha_file, extra: {type: 0}}, (captcha) => {
    if (captcha) {
      console.log('Captcha ' + captcha['captcha'] + ' solved: ' + captcha['text']);
      console.log("5");
      captchaText = captcha['text'];
      console.log("6");
    };
  });
  console.log("7");
  await page.$eval('#captchaField', el => el.value = captchaText);
  console.log("8");
  await page.click('#submitbtn');
  console.log("9");
}
I'm executing this function like this
(async () => {
// some puppeteer code
await solve_captcha(page, client, 'captcha > div', 'captcha');
// some puppeteer code
})();
Here is the output I'm getting
0
1
2
{"name":"captcha.jpg","type":"jpg","path":"./","fullPath":"./\\captcha.jpg"}
3
4captcha.jpg
7
(node:15000) UnhandledPromiseRejectionWarning: Error: Evaluation failed: ReferenceError: captchaText is not defined
(node:15000) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:15000) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. 
690.3853
Captcha 221820197 solved: XZ4xS9Lsw
5
6
I'm confused why after 4 it skips the client.decode block? Also why am I getting captchaText is not defined even when I've clearly defined it? And how to execute it correctly?
 
    