Skip to content

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.

fix: wait for storage to finish before resolving `crawler.run()`

Martin Adámek9d62d565c2ff
diff --git a/packages/basic-crawler/src/internals/basic-crawler.ts b/packages/basic-crawler/src/internals/basic-crawler.ts
index 82fef8879..adbfef1d8 100644
--- a/packages/basic-crawler/src/internals/basic-crawler.ts
+++ b/packages/basic-crawler/src/internals/basic-crawler.ts
@@ -579,6 +579,19 @@ export class BasicCrawler<Context extends CrawlingContext = BasicCrawlingContext
};
this.log.info('Crawl finished. Final request statistics:', stats);
+ const client = this.config.getStorageClient();
+
+ if (client.teardown) {
+ let finished = false;
+ setTimeout(() => {
+ if (!finished) {
+ this.log.info('Waiting for the storage to write its state to file system.');
+ }
+ }, 1000);
+ await client.teardown();
+ finished = true;
+ }
+
return stats;
}