properly catch hCaptcha window closing after timeout.

please note that you can't increase the timeout in any way, even by clicking,so the only option we have is to just reinstate the solving process
This commit is contained in:
gohoski 2025-01-08 03:10:49 +03:00
parent 9141a226b5
commit 52ad4dea00
2 changed files with 14 additions and 12 deletions

1
package-lock.json generated
View File

@ -22,7 +22,6 @@
"next-swagger-doc": "^0.4.0",
"pino": "^8.19.0",
"pino-pretty": "^11.0.0",
"playwright-core": "^1.49.1",
"react": "^18",
"react-dom": "^18",
"react-markdown": "^9.0.1",

View File

@ -300,8 +300,8 @@ class SunoApi {
new Promise<void>(async (resolve, reject) => {
const frame = page.frameLocator('iframe[title*="hCaptcha"]');
const challenge = frame.locator('.challenge-container');
while (true) {
try {
while (true) {
await page.waitForResponse('https://img**.hcaptcha.com/**', { timeout: 60000 }); // wait for hCaptcha image to load
while (true) { // wait for all requests to finish
try {
@ -354,16 +354,19 @@ class SunoApi {
await this.click(challenge, { x: +data.x, y: +data.y });
};
}
/*await*/ this.click(frame.locator('.button-submit')); // await is commented because we need to call waitForResponse at the same time
} catch(e: any) {
if (e.message.includes('viewport') || e.message.includes('timeout')) // when hCaptcha window has been closed due to inactivity,
this.click(frame.locator('.button-submit')).catch(e => {
if (e.message.includes('viewport')) // when hCaptcha window has been closed due to inactivity,
this.click(button); // click the Create button again to trigger the CAPTCHA
else if (e.message.includes('been closed')) // catch error when closing the browser
else
throw e;
});
}
} catch(e: any) {
if (e.message.includes('been closed')) // catch error when closing the browser
resolve();
else
reject(e);
}
}
}).catch(e => {
browser.browser()?.close();
throw e;
@ -409,7 +412,7 @@ class SunoApi {
): Promise<AudioInfo[]> {
await this.keepAlive(false);
const startTime = Date.now();
const audios = this.generateSongs(
const audios = await this.generateSongs(
prompt,
false,
undefined,