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.

Replacing Math.random() with cryptoRandomObjectId() in proxy sessionId generation

Marek Trunkate166b85cbc5e
diff --git a/package.json b/package.json
index dca1b234c..71e7af3da 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "apify",
- "version": "0.5.2",
+ "version": "0.5.3",
"description": "Apify Actor runtime for JavaScript",
"main": "build/index.js",
"keywords": [
diff --git a/src/puppeteer_pool.js b/src/puppeteer_pool.js
index aebb9907b..899ec8876 100644
--- a/src/puppeteer_pool.js
+++ b/src/puppeteer_pool.js
@@ -1,5 +1,6 @@
import _ from 'underscore';
import log from 'apify-shared/log';
+import { cryptoRandomObjectId } from 'apify-shared/utilities';
import { checkParamOrThrow } from 'apify-client/build/utils';
import { launchPuppeteer } from './puppeteer';
import { getApifyProxyUrl } from './actor';
@@ -38,9 +39,7 @@ const DEFAULT_OPTIONS = {
// TODO: Maybe we should move this whole logic directly to Apify.launchPuppeteer().
// E.g. if process.env.APIFY_PROXY_HOST is defined, then puppeteer should use it with "auto".
if (!disableProxy) {
- const session = Math.random();
-
- config.proxyUrl = getApifyProxyUrl({ groups, session });
+ config.proxyUrl = getApifyProxyUrl({ groups, session: cryptoRandomObjectId() });
}
return launchPuppeteer(config);