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()