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
fix: utils.apifyClient early instantiation (#1330)
Jindřich Bär077c31d6f5bf
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 507ff36bd..d0228ad8b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1,3 +1,7 @@+2.3.1 / TBA+====================+- fix: `utils.apifyClient` early instantiation (#1330)+2.3.0 / 2022/04/07====================- feat: accept more social media patterns (#1286)diff --git a/src/utils.js b/src/utils.jsindex 362db4581..0e3c597ea 100644--- a/src/utils.js+++ b/src/utils.js@@ -115,7 +115,31 @@ export const logSystemInfo = () => {* @type {*}* @ignore*/-export const apifyClient = Configuration.getGlobalConfig().getClient();+export const apifyClient = new Proxy(+ /**+ * Getting the client directly from the global Configuration invokes storage+ * creation right away during the module import. Using the proxy object delays this+ * until the first time the client is accessed.+ * This allows the user to set the envVars and other options before the client is+ * actually used.+ */+ {},+ {+ get(target, prop) {+ return target[prop] ?? Reflect.get(Configuration.getGlobalConfig().getClient(), prop);+ },+ // for mocking purpose in tests+ set(target, prop, value) {+ target[prop] = value;+ return true;+ },+ getOwnPropertyDescriptor(target, prop) {+ return Reflect.getOwnPropertyDescriptor(Configuration.getGlobalConfig().getClient(), prop);+ },+ getPrototypeOf() {+ return Object.getPrototypeOf(Configuration.getGlobalConfig().getClient());+ },+ });/*** Adds charset=utf-8 to given content type if this parameter is missing.