From f08a89b1f8078c5b895db2a2410438aa9868c6af Mon Sep 17 00:00:00 2001 From: JounQin Date: Thu, 14 Dec 2023 19:45:14 +0800 Subject: [PATCH] fix: re-pull latest anchor element after refreshing related #5 --- src/index.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 44cedc6c..bd363932 100644 --- a/src/index.ts +++ b/src/index.ts @@ -57,11 +57,9 @@ export const fetchJsUrl = async ({ { waitUntil: 'networkidle0' }, ) - const anchor = await page.waitForSelector('a#J_cdn_type_svgsymbol') + let anchor = await page.waitForSelector('a#J_cdn_type_svgsymbol') - const copy = await page.$('.project-code-top .cover-btn:not(:last-child)') - - if (copy) { + if (await page.$('.project-code-top .cover-btn:not(:last-child)')) { const refresh = await page.$('.project-code-top .cover-btn:last-child') await refresh!.click() const button = await page.waitForSelector( @@ -76,6 +74,9 @@ export const fetchJsUrl = async ({ ) } + // re-pull latest anchor element after refreshing + anchor = await page.waitForSelector('a#J_cdn_type_svgsymbol') + const jsUrl = await anchor!.evaluate(el => el.href) await browser.close()