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
refactor: handle `jsdomError` event in JSDOM virtual console
Martin Adámekdc60f0c0b39a
diff --git a/packages/jsdom-crawler/src/internals/jsdom-crawler.ts b/packages/jsdom-crawler/src/internals/jsdom-crawler.tsindex 223aa391c..9a4ed0cbc 100644--- a/packages/jsdom-crawler/src/internals/jsdom-crawler.ts+++ b/packages/jsdom-crawler/src/internals/jsdom-crawler.ts@@ -190,13 +190,17 @@ export class JSDOMCrawler extends HttpCrawler<JSDOMCrawlingContext> {this.virtualConsole.sendTo(console);}}++ this.virtualConsole.on('jsdomError', this.jsdomErrorHandler);+return this.virtualConsole;}+ private readonly jsdomErrorHandler = (error: Error) => this.log.debug('JSDOM error from console', error);+protected override async _cleanupContext(context: JSDOMCrawlingContext) {- setTimeout(() => {- context.window?.close();- }, 5_000);+ this.getVirtualConsole().off('jsdomError', this.jsdomErrorHandler);+ context.window?.close();}protected override async _parseHTML(response: IncomingMessage, isXml: boolean, crawlingContext: JSDOMCrawlingContext) {