Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

fix(js-sdk): add webhook option to startExtract and extract methods (#3318)

Jaydeep pipaliya0aafb280f4da
diff --git a/apps/js-sdk/firecrawl/package.json b/apps/js-sdk/firecrawl/package.json
index 93c00bce8..ff06fbdc8 100644
--- a/apps/js-sdk/firecrawl/package.json
+++ b/apps/js-sdk/firecrawl/package.json
@@ -1,6 +1,6 @@
{
"name": "@mendable/firecrawl-js",
- "version": "4.28.2",
+ "version": "4.28.3",
"description": "JavaScript SDK for Firecrawl API",
"main": "dist/index.js",
"types": "dist/index.d.ts",
diff --git a/apps/js-sdk/firecrawl/src/__tests__/unit/v2/extract.unit.test.ts b/apps/js-sdk/firecrawl/src/__tests__/unit/v2/extract.unit.test.ts
new file mode 100644
index 000000000..d292c3e4a
--- /dev/null
+++ b/apps/js-sdk/firecrawl/src/__tests__/unit/v2/extract.unit.test.ts
@@ -0,0 +1,47 @@
+import { describe, expect, test } from "@jest/globals";
+import { startExtract } from "../../../v2/methods/extract";
+import type { WebhookConfig } from "../../../v2/types";
+
+describe("v2.extract unit", () => {
+ test("startExtract forwards string webhook in request payload", async () => {
+ const post = jest.fn().mockResolvedValue({
+ status: 200,
+ data: { id: "extract-job" },
+ });
+
+ await startExtract({ post } as any, {
+ urls: ["https://example.com"],
+ prompt: "Extract title",
+ webhook: "https://example.com/webhook",
+ });
+
+ expect(post).toHaveBeenCalledWith("/v2/extract", {
+ urls: ["https://example.com"],
+ prompt: "Extract title",
+ webhook: "https://example.com/webhook",
+ });
+ });
+
+ test("startExtract forwards object webhook in request payload", async () => {
+ const post = jest.fn().mockResolvedValue({
+ status: 200,
+ data: { id: "extract-job" },
+ });
+ const webhook: WebhookConfig = {
+ url: "https://example.com/webhook",
+ headers: { "x-signature": "secret" },
+ };
+
+ await startExtract({ post } as any, {
+ urls: ["https://example.com"],
+ prompt: "Extract title",
+ webhook,
+ });
+
+ expect(post).toHaveBeenCalledWith("/v2/extract", {
+ urls: ["https://example.com"],
+ prompt: "Extract title",
+ webhook,
+ });
+ });
+});
diff --git a/apps/js-sdk/firecrawl/src/v2/methods/extract.ts b/apps/js-sdk/firecrawl/src/v2/methods/extract.ts
index 1b10b21b4..84e59218f 100644
--- a/apps/js-sdk/firecrawl/src/v2/methods/extract.ts
+++ b/apps/js-sdk/firecrawl/src/v2/methods/extract.ts
@@ -1,4 +1,4 @@
-import { type ExtractResponse, type ScrapeOptions, type AgentOptions } from "../types";
+import { type ExtractResponse, type ScrapeOptions, type AgentOptions, type WebhookConfig } from "../types";
import { HttpClient } from "../utils/httpClient";
import { ensureValidScrapeOptions } from "../utils/validation";
import { normalizeAxiosError, throwForBadResponse } from "../utils/errorHandler";
@@ -18,6 +18,7 @@ function prepareExtractPayload(args: {
integration?: string;
origin?: string;
agent?: AgentOptions;
+ webhook?: string | WebhookConfig | null;
}): Record<string, unknown> {
const body: Record<string, unknown> = {};
if (args.urls) body.urls = args.urls;
@@ -33,6 +34,7 @@ function prepareExtractPayload(args: {
if (args.integration && args.integration.trim()) body.integration = args.integration.trim();
if (args.origin) body.origin = args.origin;
if (args.agent) body.agent = args.agent;
+ if (args.webhook != null) body.webhook = args.webhook;
if (args.scrapeOptions) {
ensureValidScrapeOptions(args.scrapeOptions);
body.scrapeOptions = args.scrapeOptions;