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:
parent
9141a226b5
commit
52ad4dea00
1
package-lock.json
generated
1
package-lock.json
generated
@ -22,7 +22,6 @@
|
|||||||
"next-swagger-doc": "^0.4.0",
|
"next-swagger-doc": "^0.4.0",
|
||||||
"pino": "^8.19.0",
|
"pino": "^8.19.0",
|
||||||
"pino-pretty": "^11.0.0",
|
"pino-pretty": "^11.0.0",
|
||||||
"playwright-core": "^1.49.1",
|
|
||||||
"react": "^18",
|
"react": "^18",
|
||||||
"react-dom": "^18",
|
"react-dom": "^18",
|
||||||
"react-markdown": "^9.0.1",
|
"react-markdown": "^9.0.1",
|
||||||
|
@ -300,8 +300,8 @@ class SunoApi {
|
|||||||
new Promise<void>(async (resolve, reject) => {
|
new Promise<void>(async (resolve, reject) => {
|
||||||
const frame = page.frameLocator('iframe[title*="hCaptcha"]');
|
const frame = page.frameLocator('iframe[title*="hCaptcha"]');
|
||||||
const challenge = frame.locator('.challenge-container');
|
const challenge = frame.locator('.challenge-container');
|
||||||
while (true) {
|
try {
|
||||||
try {
|
while (true) {
|
||||||
await page.waitForResponse('https://img**.hcaptcha.com/**', { timeout: 60000 }); // wait for hCaptcha image to load
|
await page.waitForResponse('https://img**.hcaptcha.com/**', { timeout: 60000 }); // wait for hCaptcha image to load
|
||||||
while (true) { // wait for all requests to finish
|
while (true) { // wait for all requests to finish
|
||||||
try {
|
try {
|
||||||
@ -354,15 +354,18 @@ class SunoApi {
|
|||||||
await this.click(challenge, { x: +data.x, y: +data.y });
|
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
|
this.click(frame.locator('.button-submit')).catch(e => {
|
||||||
} catch(e: any) {
|
if (e.message.includes('viewport')) // when hCaptcha window has been closed due to inactivity,
|
||||||
if (e.message.includes('viewport') || e.message.includes('timeout')) // when hCaptcha window has been closed due to inactivity,
|
this.click(button); // click the Create button again to trigger the CAPTCHA
|
||||||
this.click(button); // click the Create button again to trigger the CAPTCHA
|
else
|
||||||
else if (e.message.includes('been closed')) // catch error when closing the browser
|
throw e;
|
||||||
resolve();
|
});
|
||||||
else
|
|
||||||
reject(e);
|
|
||||||
}
|
}
|
||||||
|
} catch(e: any) {
|
||||||
|
if (e.message.includes('been closed')) // catch error when closing the browser
|
||||||
|
resolve();
|
||||||
|
else
|
||||||
|
reject(e);
|
||||||
}
|
}
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
browser.browser()?.close();
|
browser.browser()?.close();
|
||||||
@ -409,7 +412,7 @@ class SunoApi {
|
|||||||
): Promise<AudioInfo[]> {
|
): Promise<AudioInfo[]> {
|
||||||
await this.keepAlive(false);
|
await this.keepAlive(false);
|
||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
const audios = this.generateSongs(
|
const audios = await this.generateSongs(
|
||||||
prompt,
|
prompt,
|
||||||
false,
|
false,
|
||||||
undefined,
|
undefined,
|
||||||
|
Loading…
Reference in New Issue
Block a user