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.

Evaluate concurrently

Ondra Urbanfe39606ef819
diff --git a/src/puppeteer_utils.js b/src/puppeteer_utils.js
index 1466392b1..8f956c0cc 100644
--- a/src/puppeteer_utils.js
+++ b/src/puppeteer_utils.js
@@ -76,9 +76,10 @@ const injectFile = async (page, filePath, options = {}) => {
checkParamOrThrow(options, 'options', 'Object');
const contents = await readFilePromised(filePath, 'utf8');
- if (options.surviveNavigations) await page.evaluateOnNewDocument(contents);
-
- return page.evaluate(contents);
+ const evalP = page.evaluate(contents);
+ return options.surviveNavigations
+ ? Promise.all([page.evaluateOnNewDocument(contents), evalP])
+ : evalP;
};
/**