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
Updated how we check local runs + test
drobnikjaf4907019b5b
diff --git a/src/actor.js b/src/actor.jsindex 40e4f0cf1..ac58d79fa 100644--- a/src/actor.js+++ b/src/actor.js@@ -7,7 +7,7 @@ import { APIFY_PROXY_VALUE_REGEX } from 'apify-shared/regexs';import { ENV_VARS, INTEGER_ENV_VARS, LOCAL_ENV_VARS, ACT_JOB_TERMINAL_STATUSES, ACT_JOB_STATUSES } from 'apify-shared/consts';import { EXIT_CODES } from './constants';import { initializeEvents, stopEvents } from './events';-import { apifyClient, addCharsetToContentType, sleep, snakeCaseToCamelCase } from './utils';+import { apifyClient, addCharsetToContentType, sleep, snakeCaseToCamelCase, isAtHome } from './utils';import { maybeStringify } from './key_value_store';import { ApifyCallError } from './errors';@@ -787,13 +787,17 @@ export const webhook = async ({ eventTypes, requestUrl }) => {checkParamOrThrow(eventTypes, 'eventTypes', '[String]');checkParamOrThrow(requestUrl, 'requestUrl', 'String');- const runId = process.env[ENV_VARS.ACTOR_RUN_ID];- if (!runId) {+ if (!isAtHome()) {log.warning('Apify.webhook() is only supported when running on the Apify platform. The webhook will not be invoked.');return;}- const webhook = await apifyClient.webhooks.createWebhook({+ const runId = process.env[ENV_VARS.ACTOR_RUN_ID];+ if (!runId) {+ throw new Error(`Environment variable ${ENV_VARS.ACTOR_RUN_ID} must be provided!`);+ }++ return apifyClient.webhooks.createWebhook({isAdHoc: true,eventTypes,condition: {@@ -801,6 +805,4 @@ export const webhook = async ({ eventTypes, requestUrl }) => {},requestUrl,});-- return webhook;};diff --git a/test/actor.js b/test/actor.jsindex da18c1c5e..a5ec5e36d 100644--- a/test/actor.js+++ b/test/actor.js@@ -1149,6 +1149,7 @@ describe('Apify.webhook()', () => {const expectedRequestUrl = 'http://example.com/api';process.env[ENV_VARS.ACTOR_RUN_ID] = runId;+ process.env[ENV_VARS.IS_AT_HOME] = '1';const webhooksMock = sinon.mock(Apify.client.webhooks);@@ -1168,6 +1169,7 @@ describe('Apify.webhook()', () => {await Apify.webhook({ eventTypes: expectedEventTypes, requestUrl: expectedRequestUrl });delete process.env[ENV_VARS.ACTOR_RUN_ID];+ delete process.env[ENV_VARS.IS_AT_HOME];webhooksMock.verify();webhooksMock.restore();@@ -1190,4 +1192,21 @@ describe('Apify.webhook()', () => {logMock.verify();logMock.restore();});++ it('should failed without actor run ID', async () => {+ const expectedEventTypes = ['ACTOR.RUN.SUCCEEDED'];+ const expectedRequestUrl = 'http://example.com/api';++ process.env[ENV_VARS.IS_AT_HOME] = '1';++ let isThrow;+ try {+ await Apify.webhook({ eventTypes: expectedEventTypes, requestUrl: expectedRequestUrl });+ } catch (err) {+ isThrow = true;+ }+ expect(isThrow).to.be.eql(true);++ delete process.env[ENV_VARS.IS_AT_HOME];+ });});