Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.
TypeScript apifyautomationcrawlercrawlingheadlessheadless-chromejavascriptnodejsnpmplaywrightpuppeteerscraperscrapingtypescriptweb-crawlerweb-crawlingweb-scraping
Fix lint and flaky test
Ondra Urban18ca6132c01b
diff --git a/src/enqueue_links/click_elements.js b/src/enqueue_links/click_elements.jsindex 4ff76b3c4..d1f0b41e9 100644--- a/src/enqueue_links/click_elements.js+++ b/src/enqueue_links/click_elements.js@@ -389,7 +389,7 @@ async function waitForPageIdle({ page, waitForPageIdleMillis, maxWaitForPageIdle}function maxTimeoutHandler() {- log.debug(`enqueueLinksByClickingElements: Page still showed activity after ${timeoutMillis}ms. `+ log.debug(`enqueueLinksByClickingElements: Page still showed activity after ${maxWaitForPageIdleMillis}ms. `+ 'This is probably due to the website itself dispatching requests, but some links may also have been missed.');finish();}diff --git a/test/enqueue_links/click_elements.js b/test/enqueue_links/click_elements.jsindex 8909359da..5ad1d2022 100644--- a/test/enqueue_links/click_elements.js+++ b/test/enqueue_links/click_elements.js@@ -250,26 +250,6 @@ describe('enqueueLinksByClickingElements()', () => {expect(pageContent).to.include('onclick="return window.history.pushState');});- it('should save urls from newly opened tabs', async () => {- const html = `-<html>- <body>- <div onclick="return window.open('https://example.com');">div</div>- </body>-</html>- `;- await page.setContent(html);- const interceptedRequests = await clickElementsAndInterceptNavigationRequests(getOpts({- waitForPageIdleMillis: 1000,- maxWaitForPageIdleMillis: 5000,- }));- await new Promise(r => setTimeout(r, 1000));- expect(interceptedRequests).to.have.lengthOf(1);- expect(interceptedRequests[0].url).to.be.eql('https://example.com/');- const pageContent = await page.content();- expect(pageContent).to.include('onclick="return window.open(');- });-it('should close newly opened tabs', async () => {const html = `<html>@@ -293,10 +273,10 @@ describe('enqueueLinksByClickingElements()', () => {counts.destroy++;if (spawnedTarget === target) resolve(counts);});- await clickElementsAndInterceptNavigationRequests(getOpts({+ clickElementsAndInterceptNavigationRequests(getOpts({waitForPageIdleMillis: 1000,maxWaitForPageIdleMillis: 5000,- }));+ })).catch(() => { /* will throw because afterEach will close the page */ });});expect(callCounts.create).to.be.eql(1);@@ -304,5 +284,25 @@ describe('enqueueLinksByClickingElements()', () => {const pageContent = await page.content();expect(pageContent).to.include('onclick="return window.open(');});++ it('should save urls from newly opened tabs', async () => {+ const html = `+<html>+ <body>+ <div onclick="return window.open('https://example.com');">div</div>+ </body>+</html>+ `;+ await page.setContent(html);+ const interceptedRequests = await clickElementsAndInterceptNavigationRequests(getOpts({+ waitForPageIdleMillis: 1000,+ maxWaitForPageIdleMillis: 5000,+ }));+ await new Promise(r => setTimeout(r, 1000));+ expect(interceptedRequests).to.have.lengthOf(1);+ expect(interceptedRequests[0].url).to.be.eql('https://example.com/');+ const pageContent = await page.content();+ expect(pageContent).to.include('onclick="return window.open(');+ });});});