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
Add warning log to enqueueByClicking when the element is detached
Ondra Urban719747fda6fe
diff --git a/src/enqueue_links/click_elements.js b/src/enqueue_links/click_elements.jsindex 5fa905b0d..01cc78f29 100644--- a/src/enqueue_links/click_elements.js+++ b/src/enqueue_links/click_elements.js@@ -323,12 +323,19 @@ export async function clickElements(page, selector) {log.debug(`enqueueLinksByClickingElements: There are ${elementHandles.length} elements to click.`);let clickedElementsCount = 0;let zIndex = STARTING_Z_INDEX;+ let shouldLogWarning = true;for (const handle of elementHandles) {try {await page.evaluate(updateElementCssToEnableMouseClick, handle, zIndex++);await handle.click();clickedElementsCount++;} catch (err) {+ if (shouldLogWarning && err.stack.includes('is detached from document')) {+ log.warning(`An element with selector ${selector} that you're trying to click has been removed from the page. `+ + 'This was probably caused by an earlier click which triggered some JavaScript on the page that caused it to change. '+ + 'If you\'re trying to enqueue pagination links, we suggest using the "next" button, if available and going one by one.');+ shouldLogWarning = false;+ }log.debug('enqueueLinksByClickingElements: Click failed.', { stack: err.stack });}}