From 44aa73e18c99813d762939e0aade69f53369ed69 Mon Sep 17 00:00:00 2001 From: geekgeekrun Date: Fri, 15 Mar 2024 09:25:20 +0800 Subject: [PATCH] when current account is limited, throw error directly --- .../geek-auto-start-chat-with-boss/index.mjs | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/geek-auto-start-chat-with-boss/index.mjs b/packages/geek-auto-start-chat-with-boss/index.mjs index 6ede9dc..7468db6 100644 --- a/packages/geek-auto-start-chat-with-boss/index.mjs +++ b/packages/geek-auto-start-chat-with-boss/index.mjs @@ -92,22 +92,27 @@ export async function mainLoop (hooks) { } await setDomainLocalStorage(browser, localStoragePageUrl, bossLocalStorage) await page.bringToFront() - let userInfoResponse - await Promise.all([ - page.goto(recommendJobPageUrl, { timeout: 0 }), - page.waitForResponse((response) => { + let userInfoPromise = page.waitForResponse((response) => { if (response.url().startsWith('https://www.zhipin.com/wapi/zpuser/wap/getUserInfo.json')) { return true } return false }).then((res) => { return res.json() - }).then((res) => { - userInfoResponse = res - }), + }) + await Promise.all([ + page.goto(recommendJobPageUrl, { timeout: 60 * 1000 }), page.waitForNavigation(), ]) + if ( + page.url().startsWith('https://www.zhipin.com/web/common/403.html') || + page.url().startsWith('https://www.zhipin.com/web/common/error.html') + ) { + throw new Error("ACCESS_IS_DENIED") + } hooks.pageLoaded?.call() + + let userInfoResponse = await userInfoPromise hooks.userInfoResponse?.call(userInfoResponse) if (userInfoResponse.code !== 0) { @@ -354,14 +359,16 @@ export async function mainLoop (hooks) { // ;await browser.close() } catch (err) { closeBrowserWindow() - - console.error(err) throw err } } export async function closeBrowserWindow () { browser?.close() + const browserProcess = browser?.process() + if (browserProcess) { + process.kill(browserProcess.pid) + } browser = null page = null }