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
Reworked how pushRecord is called
Jaroslav Hejlek7ec3ed0d1db4
diff --git a/src/actor.js b/src/actor.jsindex ec99c6368..9b5b839c5 100644--- a/src/actor.js+++ b/src/actor.js@@ -52,21 +52,11 @@ const getDefaultStoreIdOrThrow = () => {return storeId;};-let sequentialStore = null;-const getOrCreateSequentialStore = () => new Promise((resolve, reject) => {+const getDefaultSequentialStoreIdOrThrow = () => {const storeId = process.env[ENV_VARS.DEFAULT_SEQUENTIAL_STORE_ID];- if (!storeId) reject(new Error(`The '${ENV_VARS.DEFAULT_SEQUENTIAL_STORE_ID}' environment variable is not defined.`));- if (sequentialStore) return sequentialStore;-- const promisePrototype = getPromisePrototype();- apifyClient.sequentialStores.getOrCreateStoreWithId({- storeId,- promise: promisePrototype,- }).then((store) => {- sequentialStore = store;- resolve(store);- }).catch(reject);-});+ if (!storeId) throw new Error(`The '${ENV_VARS.DEFAULT_SEQUENTIAL_STORE_ID}' environment variable is not defined.`);+ return storeId;+};/**@@ -346,17 +336,17 @@ export const pushRecord = (record, callback = null) => {throw new Error('The "record" parameter cannot be stringified to JSON.');}- const promise = getOrCreateSequentialStore()- .then((store) => {- return apifyClient.sequentialStores.putRecord({- storeId: store._id,- promise: promisePrototype,- data: stringifiedRecord,- });- });+ const storeId = getDefaultSequentialStoreIdOrThrow();++ const innerPromise = apifyClient.sequentialStores.putRecord({+ storeId,+ promise: promisePrototype,+ data: stringifiedRecord,+ });// TODO: Emulation of sequential store for local development+ const promise = newPromise().then(() => innerPromise);return nodeifyPromise(promise, callback);};