@mendable/firecrawl-js 4.12.1 → 4.13.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,7 @@ var require_package = __commonJS({
8
8
  "package.json"(exports, module) {
9
9
  module.exports = {
10
10
  name: "@mendable/firecrawl-js",
11
- version: "4.12.1",
11
+ version: "4.13.0-beta.2",
12
12
  description: "JavaScript SDK for Firecrawl API",
13
13
  main: "dist/index.js",
14
14
  types: "dist/index.d.ts",
package/dist/index.cjs CHANGED
@@ -35,7 +35,7 @@ var require_package = __commonJS({
35
35
  "package.json"(exports2, module2) {
36
36
  module2.exports = {
37
37
  name: "@mendable/firecrawl-js",
38
- version: "4.12.1",
38
+ version: "4.13.0-beta.2",
39
39
  description: "JavaScript SDK for Firecrawl API",
40
40
  main: "dist/index.js",
41
41
  types: "dist/index.d.ts",
@@ -106,17 +106,17 @@ var require_package = __commonJS({
106
106
  });
107
107
 
108
108
  // src/index.ts
109
- var index_exports = {};
110
- __export(index_exports, {
109
+ var src_exports = {};
110
+ __export(src_exports, {
111
111
  Firecrawl: () => Firecrawl,
112
112
  FirecrawlAppV1: () => FirecrawlApp,
113
113
  FirecrawlClient: () => FirecrawlClient,
114
114
  JobTimeoutError: () => JobTimeoutError,
115
115
  SdkError: () => SdkError,
116
116
  Watcher: () => Watcher,
117
- default: () => index_default
117
+ default: () => src_default
118
118
  });
119
- module.exports = __toCommonJS(index_exports);
119
+ module.exports = __toCommonJS(src_exports);
120
120
 
121
121
  // src/v2/utils/httpClient.ts
122
122
  var import_axios = __toESM(require("axios"), 1);
@@ -928,6 +928,63 @@ async function cancelAgent(http, jobId) {
928
928
  }
929
929
  }
930
930
 
931
+ // src/v2/methods/browser.ts
932
+ async function browser(http, args = {}) {
933
+ const body = {};
934
+ if (args.ttlTotal != null) body.ttlTotal = args.ttlTotal;
935
+ if (args.ttlWithoutActivity != null) body.ttlWithoutActivity = args.ttlWithoutActivity;
936
+ if (args.streamWebView != null) body.streamWebView = args.streamWebView;
937
+ try {
938
+ const res = await http.post("/v2/browser", body);
939
+ if (res.status !== 200) throwForBadResponse(res, "create browser session");
940
+ return res.data;
941
+ } catch (err) {
942
+ if (err?.isAxiosError) return normalizeAxiosError(err, "create browser session");
943
+ throw err;
944
+ }
945
+ }
946
+ async function browserExecute(http, sessionId, args) {
947
+ const body = {
948
+ code: args.code,
949
+ language: args.language ?? "python"
950
+ };
951
+ try {
952
+ const res = await http.post(
953
+ `/v2/browser/${sessionId}/execute`,
954
+ body
955
+ );
956
+ if (res.status !== 200) throwForBadResponse(res, "execute browser code");
957
+ return res.data;
958
+ } catch (err) {
959
+ if (err?.isAxiosError) return normalizeAxiosError(err, "execute browser code");
960
+ throw err;
961
+ }
962
+ }
963
+ async function deleteBrowser(http, sessionId) {
964
+ try {
965
+ const res = await http.delete(
966
+ `/v2/browser/${sessionId}`
967
+ );
968
+ if (res.status !== 200) throwForBadResponse(res, "delete browser session");
969
+ return res.data;
970
+ } catch (err) {
971
+ if (err?.isAxiosError) return normalizeAxiosError(err, "delete browser session");
972
+ throw err;
973
+ }
974
+ }
975
+ async function listBrowsers(http, args = {}) {
976
+ let endpoint = "/v2/browser";
977
+ if (args.status) endpoint += `?status=${args.status}`;
978
+ try {
979
+ const res = await http.get(endpoint);
980
+ if (res.status !== 200) throwForBadResponse(res, "list browser sessions");
981
+ return res.data;
982
+ } catch (err) {
983
+ if (err?.isAxiosError) return normalizeAxiosError(err, "list browser sessions");
984
+ throw err;
985
+ }
986
+ }
987
+
931
988
  // src/v2/methods/usage.ts
932
989
  async function getConcurrency(http) {
933
990
  try {
@@ -1421,6 +1478,39 @@ var FirecrawlClient = class {
1421
1478
  async cancelAgent(jobId) {
1422
1479
  return cancelAgent(this.http, jobId);
1423
1480
  }
1481
+ // Browser
1482
+ /**
1483
+ * Create a new browser session.
1484
+ * @param args Session options (ttlTotal, ttlWithoutActivity, streamWebView).
1485
+ * @returns Session id and CDP URL.
1486
+ */
1487
+ async browser(args = {}) {
1488
+ return browser(this.http, args);
1489
+ }
1490
+ /**
1491
+ * Execute code in a browser session.
1492
+ * @param sessionId Browser session id.
1493
+ * @param args Code and language to execute.
1494
+ * @returns Execution result.
1495
+ */
1496
+ async browserExecute(sessionId, args) {
1497
+ return browserExecute(this.http, sessionId, args);
1498
+ }
1499
+ /**
1500
+ * Delete a browser session.
1501
+ * @param sessionId Browser session id.
1502
+ */
1503
+ async deleteBrowser(sessionId) {
1504
+ return deleteBrowser(this.http, sessionId);
1505
+ }
1506
+ /**
1507
+ * List browser sessions.
1508
+ * @param args Optional filter (status: "active" | "destroyed").
1509
+ * @returns List of browser sessions.
1510
+ */
1511
+ async listBrowsers(args = {}) {
1512
+ return listBrowsers(this.http, args);
1513
+ }
1424
1514
  // Usage
1425
1515
  /** Current concurrency usage. */
1426
1516
  async getConcurrency() {
@@ -1461,7 +1551,7 @@ var FirecrawlClient = class {
1461
1551
  var import_axios3 = __toESM(require("axios"), 1);
1462
1552
  var zt2 = require("zod");
1463
1553
 
1464
- // node_modules/.pnpm/typescript-event-target@1.1.1/node_modules/typescript-event-target/dist/index.mjs
1554
+ // node_modules/typescript-event-target/dist/index.mjs
1465
1555
  var e = class extends EventTarget {
1466
1556
  dispatchTypedEvent(s, t) {
1467
1557
  return super.dispatchEvent(t);
@@ -2861,7 +2951,7 @@ var Firecrawl = class extends FirecrawlClient {
2861
2951
  return this._v1;
2862
2952
  }
2863
2953
  };
2864
- var index_default = Firecrawl;
2954
+ var src_default = Firecrawl;
2865
2955
  // Annotate the CommonJS export names for ESM import in node:
2866
2956
  0 && (module.exports = {
2867
2957
  Firecrawl,
package/dist/index.d.cts CHANGED
@@ -554,6 +554,36 @@ interface QueueStatusResponse$1 {
554
554
  maxConcurrency: number;
555
555
  mostRecentSuccess: string | null;
556
556
  }
557
+ interface BrowserCreateResponse {
558
+ success: boolean;
559
+ id?: string;
560
+ cdpUrl?: string;
561
+ liveViewUrl?: string;
562
+ error?: string;
563
+ }
564
+ interface BrowserExecuteResponse {
565
+ success: boolean;
566
+ result?: string;
567
+ error?: string;
568
+ }
569
+ interface BrowserDeleteResponse {
570
+ success: boolean;
571
+ error?: string;
572
+ }
573
+ interface BrowserSession {
574
+ id: string;
575
+ status: string;
576
+ cdpUrl: string;
577
+ liveViewUrl: string;
578
+ streamWebView: boolean;
579
+ createdAt: string;
580
+ lastActivity: string;
581
+ }
582
+ interface BrowserListResponse {
583
+ success: boolean;
584
+ sessions?: BrowserSession[];
585
+ error?: string;
586
+ }
557
587
 
558
588
  interface HttpClientOptions {
559
589
  apiKey: string;
@@ -573,9 +603,9 @@ declare class HttpClient {
573
603
  getApiKey(): string;
574
604
  private request;
575
605
  private sleep;
576
- post<T = any>(endpoint: string, body: Record<string, unknown>, headers?: Record<string, string>): Promise<AxiosResponse<T, any, {}>>;
577
- get<T = any>(endpoint: string, headers?: Record<string, string>): Promise<AxiosResponse<T, any, {}>>;
578
- delete<T = any>(endpoint: string, headers?: Record<string, string>): Promise<AxiosResponse<T, any, {}>>;
606
+ post<T = any>(endpoint: string, body: Record<string, unknown>, headers?: Record<string, string>): Promise<AxiosResponse<T, any>>;
607
+ get<T = any>(endpoint: string, headers?: Record<string, string>): Promise<AxiosResponse<T, any>>;
608
+ delete<T = any>(endpoint: string, headers?: Record<string, string>): Promise<AxiosResponse<T, any>>;
579
609
  prepareHeaders(idempotencyKey?: string): Record<string, string>;
580
610
  }
581
611
 
@@ -606,6 +636,19 @@ declare function prepareAgentPayload(args: {
606
636
  }): Record<string, unknown>;
607
637
  declare function startAgent(http: HttpClient, args: Parameters<typeof prepareAgentPayload>[0]): Promise<AgentResponse>;
608
638
 
639
+ declare function browser(http: HttpClient, args?: {
640
+ ttlTotal?: number;
641
+ ttlWithoutActivity?: number;
642
+ streamWebView?: boolean;
643
+ }): Promise<BrowserCreateResponse>;
644
+ declare function browserExecute(http: HttpClient, sessionId: string, args: {
645
+ code: string;
646
+ language?: "python" | "js";
647
+ }): Promise<BrowserExecuteResponse>;
648
+ declare function listBrowsers(http: HttpClient, args?: {
649
+ status?: "active" | "destroyed";
650
+ }): Promise<BrowserListResponse>;
651
+
609
652
  type JobKind = "crawl" | "batch";
610
653
  interface WatcherOptions {
611
654
  kind?: JobKind;
@@ -811,6 +854,30 @@ declare class FirecrawlClient {
811
854
  * @returns True if cancelled.
812
855
  */
813
856
  cancelAgent(jobId: string): Promise<boolean>;
857
+ /**
858
+ * Create a new browser session.
859
+ * @param args Session options (ttlTotal, ttlWithoutActivity, streamWebView).
860
+ * @returns Session id and CDP URL.
861
+ */
862
+ browser(args?: Parameters<typeof browser>[1]): Promise<BrowserCreateResponse>;
863
+ /**
864
+ * Execute code in a browser session.
865
+ * @param sessionId Browser session id.
866
+ * @param args Code and language to execute.
867
+ * @returns Execution result.
868
+ */
869
+ browserExecute(sessionId: string, args: Parameters<typeof browserExecute>[2]): Promise<BrowserExecuteResponse>;
870
+ /**
871
+ * Delete a browser session.
872
+ * @param sessionId Browser session id.
873
+ */
874
+ deleteBrowser(sessionId: string): Promise<BrowserDeleteResponse>;
875
+ /**
876
+ * List browser sessions.
877
+ * @param args Optional filter (status: "active" | "destroyed").
878
+ * @returns List of browser sessions.
879
+ */
880
+ listBrowsers(args?: Parameters<typeof listBrowsers>[1]): Promise<BrowserListResponse>;
814
881
  /** Current concurrency usage. */
815
882
  getConcurrency(): Promise<ConcurrencyCheck>;
816
883
  /** Current credit usage. */
@@ -1736,4 +1803,4 @@ declare class Firecrawl extends FirecrawlClient {
1736
1803
  get v1(): FirecrawlApp;
1737
1804
  }
1738
1805
 
1739
- export { type ActionOption, type ActiveCrawl, type ActiveCrawlsResponse, type AgentOptions$1 as AgentOptions, type AgentResponse, type AgentStatusResponse, type AgentWebhookConfig, type AgentWebhookEvent, type AttributesFormat, type BatchScrapeJob, type BatchScrapeOptions, type BatchScrapeResponse$1 as BatchScrapeResponse, type BrandingProfile, type CategoryOption, type ChangeTrackingFormat, type ClickAction, type ConcurrencyCheck, type CrawlErrorsResponse$1 as CrawlErrorsResponse, type CrawlJob, type CrawlOptions, type CrawlResponse$1 as CrawlResponse, type CreditUsage, type CreditUsageHistoricalPeriod, type CreditUsageHistoricalResponse, type Document, type DocumentMetadata, type ErrorDetails, type ExecuteJavascriptAction, type ExtractResponse$1 as ExtractResponse, Firecrawl, FirecrawlApp as FirecrawlAppV1, FirecrawlClient, type FirecrawlClientOptions, type Format, type FormatOption, type FormatString, JobTimeoutError, type JsonFormat, type LocationConfig$1 as LocationConfig, type MapData, type MapOptions, type PDFAction, type PaginationConfig, type PressAction, type QueueStatusResponse$1 as QueueStatusResponse, type ScrapeAction, type ScrapeOptions, type ScreenshotAction, type ScreenshotFormat, type ScrollAction, SdkError, type SearchData, type SearchRequest, type SearchResultImages, type SearchResultNews, type SearchResultWeb, type TokenUsage, type TokenUsageHistoricalPeriod, type TokenUsageHistoricalResponse, type Viewport, type WaitAction, Watcher, type WatcherOptions, type WebhookConfig, type WriteAction, Firecrawl as default };
1806
+ export { type ActionOption, type ActiveCrawl, type ActiveCrawlsResponse, type AgentOptions$1 as AgentOptions, type AgentResponse, type AgentStatusResponse, type AgentWebhookConfig, type AgentWebhookEvent, type AttributesFormat, type BatchScrapeJob, type BatchScrapeOptions, type BatchScrapeResponse$1 as BatchScrapeResponse, type BrandingProfile, type BrowserCreateResponse, type BrowserDeleteResponse, type BrowserExecuteResponse, type BrowserListResponse, type BrowserSession, type CategoryOption, type ChangeTrackingFormat, type ClickAction, type ConcurrencyCheck, type CrawlErrorsResponse$1 as CrawlErrorsResponse, type CrawlJob, type CrawlOptions, type CrawlResponse$1 as CrawlResponse, type CreditUsage, type CreditUsageHistoricalPeriod, type CreditUsageHistoricalResponse, type Document, type DocumentMetadata, type ErrorDetails, type ExecuteJavascriptAction, type ExtractResponse$1 as ExtractResponse, Firecrawl, FirecrawlApp as FirecrawlAppV1, FirecrawlClient, type FirecrawlClientOptions, type Format, type FormatOption, type FormatString, JobTimeoutError, type JsonFormat, type LocationConfig$1 as LocationConfig, type MapData, type MapOptions, type PDFAction, type PaginationConfig, type PressAction, type QueueStatusResponse$1 as QueueStatusResponse, type ScrapeAction, type ScrapeOptions, type ScreenshotAction, type ScreenshotFormat, type ScrollAction, SdkError, type SearchData, type SearchRequest, type SearchResultImages, type SearchResultNews, type SearchResultWeb, type TokenUsage, type TokenUsageHistoricalPeriod, type TokenUsageHistoricalResponse, type Viewport, type WaitAction, Watcher, type WatcherOptions, type WebhookConfig, type WriteAction, Firecrawl as default };
package/dist/index.d.ts CHANGED
@@ -554,6 +554,36 @@ interface QueueStatusResponse$1 {
554
554
  maxConcurrency: number;
555
555
  mostRecentSuccess: string | null;
556
556
  }
557
+ interface BrowserCreateResponse {
558
+ success: boolean;
559
+ id?: string;
560
+ cdpUrl?: string;
561
+ liveViewUrl?: string;
562
+ error?: string;
563
+ }
564
+ interface BrowserExecuteResponse {
565
+ success: boolean;
566
+ result?: string;
567
+ error?: string;
568
+ }
569
+ interface BrowserDeleteResponse {
570
+ success: boolean;
571
+ error?: string;
572
+ }
573
+ interface BrowserSession {
574
+ id: string;
575
+ status: string;
576
+ cdpUrl: string;
577
+ liveViewUrl: string;
578
+ streamWebView: boolean;
579
+ createdAt: string;
580
+ lastActivity: string;
581
+ }
582
+ interface BrowserListResponse {
583
+ success: boolean;
584
+ sessions?: BrowserSession[];
585
+ error?: string;
586
+ }
557
587
 
558
588
  interface HttpClientOptions {
559
589
  apiKey: string;
@@ -573,9 +603,9 @@ declare class HttpClient {
573
603
  getApiKey(): string;
574
604
  private request;
575
605
  private sleep;
576
- post<T = any>(endpoint: string, body: Record<string, unknown>, headers?: Record<string, string>): Promise<AxiosResponse<T, any, {}>>;
577
- get<T = any>(endpoint: string, headers?: Record<string, string>): Promise<AxiosResponse<T, any, {}>>;
578
- delete<T = any>(endpoint: string, headers?: Record<string, string>): Promise<AxiosResponse<T, any, {}>>;
606
+ post<T = any>(endpoint: string, body: Record<string, unknown>, headers?: Record<string, string>): Promise<AxiosResponse<T, any>>;
607
+ get<T = any>(endpoint: string, headers?: Record<string, string>): Promise<AxiosResponse<T, any>>;
608
+ delete<T = any>(endpoint: string, headers?: Record<string, string>): Promise<AxiosResponse<T, any>>;
579
609
  prepareHeaders(idempotencyKey?: string): Record<string, string>;
580
610
  }
581
611
 
@@ -606,6 +636,19 @@ declare function prepareAgentPayload(args: {
606
636
  }): Record<string, unknown>;
607
637
  declare function startAgent(http: HttpClient, args: Parameters<typeof prepareAgentPayload>[0]): Promise<AgentResponse>;
608
638
 
639
+ declare function browser(http: HttpClient, args?: {
640
+ ttlTotal?: number;
641
+ ttlWithoutActivity?: number;
642
+ streamWebView?: boolean;
643
+ }): Promise<BrowserCreateResponse>;
644
+ declare function browserExecute(http: HttpClient, sessionId: string, args: {
645
+ code: string;
646
+ language?: "python" | "js";
647
+ }): Promise<BrowserExecuteResponse>;
648
+ declare function listBrowsers(http: HttpClient, args?: {
649
+ status?: "active" | "destroyed";
650
+ }): Promise<BrowserListResponse>;
651
+
609
652
  type JobKind = "crawl" | "batch";
610
653
  interface WatcherOptions {
611
654
  kind?: JobKind;
@@ -811,6 +854,30 @@ declare class FirecrawlClient {
811
854
  * @returns True if cancelled.
812
855
  */
813
856
  cancelAgent(jobId: string): Promise<boolean>;
857
+ /**
858
+ * Create a new browser session.
859
+ * @param args Session options (ttlTotal, ttlWithoutActivity, streamWebView).
860
+ * @returns Session id and CDP URL.
861
+ */
862
+ browser(args?: Parameters<typeof browser>[1]): Promise<BrowserCreateResponse>;
863
+ /**
864
+ * Execute code in a browser session.
865
+ * @param sessionId Browser session id.
866
+ * @param args Code and language to execute.
867
+ * @returns Execution result.
868
+ */
869
+ browserExecute(sessionId: string, args: Parameters<typeof browserExecute>[2]): Promise<BrowserExecuteResponse>;
870
+ /**
871
+ * Delete a browser session.
872
+ * @param sessionId Browser session id.
873
+ */
874
+ deleteBrowser(sessionId: string): Promise<BrowserDeleteResponse>;
875
+ /**
876
+ * List browser sessions.
877
+ * @param args Optional filter (status: "active" | "destroyed").
878
+ * @returns List of browser sessions.
879
+ */
880
+ listBrowsers(args?: Parameters<typeof listBrowsers>[1]): Promise<BrowserListResponse>;
814
881
  /** Current concurrency usage. */
815
882
  getConcurrency(): Promise<ConcurrencyCheck>;
816
883
  /** Current credit usage. */
@@ -1736,4 +1803,4 @@ declare class Firecrawl extends FirecrawlClient {
1736
1803
  get v1(): FirecrawlApp;
1737
1804
  }
1738
1805
 
1739
- export { type ActionOption, type ActiveCrawl, type ActiveCrawlsResponse, type AgentOptions$1 as AgentOptions, type AgentResponse, type AgentStatusResponse, type AgentWebhookConfig, type AgentWebhookEvent, type AttributesFormat, type BatchScrapeJob, type BatchScrapeOptions, type BatchScrapeResponse$1 as BatchScrapeResponse, type BrandingProfile, type CategoryOption, type ChangeTrackingFormat, type ClickAction, type ConcurrencyCheck, type CrawlErrorsResponse$1 as CrawlErrorsResponse, type CrawlJob, type CrawlOptions, type CrawlResponse$1 as CrawlResponse, type CreditUsage, type CreditUsageHistoricalPeriod, type CreditUsageHistoricalResponse, type Document, type DocumentMetadata, type ErrorDetails, type ExecuteJavascriptAction, type ExtractResponse$1 as ExtractResponse, Firecrawl, FirecrawlApp as FirecrawlAppV1, FirecrawlClient, type FirecrawlClientOptions, type Format, type FormatOption, type FormatString, JobTimeoutError, type JsonFormat, type LocationConfig$1 as LocationConfig, type MapData, type MapOptions, type PDFAction, type PaginationConfig, type PressAction, type QueueStatusResponse$1 as QueueStatusResponse, type ScrapeAction, type ScrapeOptions, type ScreenshotAction, type ScreenshotFormat, type ScrollAction, SdkError, type SearchData, type SearchRequest, type SearchResultImages, type SearchResultNews, type SearchResultWeb, type TokenUsage, type TokenUsageHistoricalPeriod, type TokenUsageHistoricalResponse, type Viewport, type WaitAction, Watcher, type WatcherOptions, type WebhookConfig, type WriteAction, Firecrawl as default };
1806
+ export { type ActionOption, type ActiveCrawl, type ActiveCrawlsResponse, type AgentOptions$1 as AgentOptions, type AgentResponse, type AgentStatusResponse, type AgentWebhookConfig, type AgentWebhookEvent, type AttributesFormat, type BatchScrapeJob, type BatchScrapeOptions, type BatchScrapeResponse$1 as BatchScrapeResponse, type BrandingProfile, type BrowserCreateResponse, type BrowserDeleteResponse, type BrowserExecuteResponse, type BrowserListResponse, type BrowserSession, type CategoryOption, type ChangeTrackingFormat, type ClickAction, type ConcurrencyCheck, type CrawlErrorsResponse$1 as CrawlErrorsResponse, type CrawlJob, type CrawlOptions, type CrawlResponse$1 as CrawlResponse, type CreditUsage, type CreditUsageHistoricalPeriod, type CreditUsageHistoricalResponse, type Document, type DocumentMetadata, type ErrorDetails, type ExecuteJavascriptAction, type ExtractResponse$1 as ExtractResponse, Firecrawl, FirecrawlApp as FirecrawlAppV1, FirecrawlClient, type FirecrawlClientOptions, type Format, type FormatOption, type FormatString, JobTimeoutError, type JsonFormat, type LocationConfig$1 as LocationConfig, type MapData, type MapOptions, type PDFAction, type PaginationConfig, type PressAction, type QueueStatusResponse$1 as QueueStatusResponse, type ScrapeAction, type ScrapeOptions, type ScreenshotAction, type ScreenshotFormat, type ScrollAction, SdkError, type SearchData, type SearchRequest, type SearchResultImages, type SearchResultNews, type SearchResultWeb, type TokenUsage, type TokenUsageHistoricalPeriod, type TokenUsageHistoricalResponse, type Viewport, type WaitAction, Watcher, type WatcherOptions, type WebhookConfig, type WriteAction, Firecrawl as default };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  require_package
3
- } from "./chunk-GAAHPN3I.js";
3
+ } from "./chunk-VEC6CWSH.js";
4
4
 
5
5
  // src/v2/utils/httpClient.ts
6
6
  import axios from "axios";
@@ -812,6 +812,63 @@ async function cancelAgent(http, jobId) {
812
812
  }
813
813
  }
814
814
 
815
+ // src/v2/methods/browser.ts
816
+ async function browser(http, args = {}) {
817
+ const body = {};
818
+ if (args.ttlTotal != null) body.ttlTotal = args.ttlTotal;
819
+ if (args.ttlWithoutActivity != null) body.ttlWithoutActivity = args.ttlWithoutActivity;
820
+ if (args.streamWebView != null) body.streamWebView = args.streamWebView;
821
+ try {
822
+ const res = await http.post("/v2/browser", body);
823
+ if (res.status !== 200) throwForBadResponse(res, "create browser session");
824
+ return res.data;
825
+ } catch (err) {
826
+ if (err?.isAxiosError) return normalizeAxiosError(err, "create browser session");
827
+ throw err;
828
+ }
829
+ }
830
+ async function browserExecute(http, sessionId, args) {
831
+ const body = {
832
+ code: args.code,
833
+ language: args.language ?? "python"
834
+ };
835
+ try {
836
+ const res = await http.post(
837
+ `/v2/browser/${sessionId}/execute`,
838
+ body
839
+ );
840
+ if (res.status !== 200) throwForBadResponse(res, "execute browser code");
841
+ return res.data;
842
+ } catch (err) {
843
+ if (err?.isAxiosError) return normalizeAxiosError(err, "execute browser code");
844
+ throw err;
845
+ }
846
+ }
847
+ async function deleteBrowser(http, sessionId) {
848
+ try {
849
+ const res = await http.delete(
850
+ `/v2/browser/${sessionId}`
851
+ );
852
+ if (res.status !== 200) throwForBadResponse(res, "delete browser session");
853
+ return res.data;
854
+ } catch (err) {
855
+ if (err?.isAxiosError) return normalizeAxiosError(err, "delete browser session");
856
+ throw err;
857
+ }
858
+ }
859
+ async function listBrowsers(http, args = {}) {
860
+ let endpoint = "/v2/browser";
861
+ if (args.status) endpoint += `?status=${args.status}`;
862
+ try {
863
+ const res = await http.get(endpoint);
864
+ if (res.status !== 200) throwForBadResponse(res, "list browser sessions");
865
+ return res.data;
866
+ } catch (err) {
867
+ if (err?.isAxiosError) return normalizeAxiosError(err, "list browser sessions");
868
+ throw err;
869
+ }
870
+ }
871
+
815
872
  // src/v2/methods/usage.ts
816
873
  async function getConcurrency(http) {
817
874
  try {
@@ -902,7 +959,7 @@ var loadPromise;
902
959
  var loadNodeWebSocket = async () => {
903
960
  if (!isNodeRuntime()) return void 0;
904
961
  try {
905
- const undici = await import("undici");
962
+ const undici = await import("node:undici");
906
963
  const ctor = undici.WebSocket ?? undici.default?.WebSocket;
907
964
  return typeof ctor === "function" ? ctor : void 0;
908
965
  } catch {
@@ -1305,6 +1362,39 @@ var FirecrawlClient = class {
1305
1362
  async cancelAgent(jobId) {
1306
1363
  return cancelAgent(this.http, jobId);
1307
1364
  }
1365
+ // Browser
1366
+ /**
1367
+ * Create a new browser session.
1368
+ * @param args Session options (ttlTotal, ttlWithoutActivity, streamWebView).
1369
+ * @returns Session id and CDP URL.
1370
+ */
1371
+ async browser(args = {}) {
1372
+ return browser(this.http, args);
1373
+ }
1374
+ /**
1375
+ * Execute code in a browser session.
1376
+ * @param sessionId Browser session id.
1377
+ * @param args Code and language to execute.
1378
+ * @returns Execution result.
1379
+ */
1380
+ async browserExecute(sessionId, args) {
1381
+ return browserExecute(this.http, sessionId, args);
1382
+ }
1383
+ /**
1384
+ * Delete a browser session.
1385
+ * @param sessionId Browser session id.
1386
+ */
1387
+ async deleteBrowser(sessionId) {
1388
+ return deleteBrowser(this.http, sessionId);
1389
+ }
1390
+ /**
1391
+ * List browser sessions.
1392
+ * @param args Optional filter (status: "active" | "destroyed").
1393
+ * @returns List of browser sessions.
1394
+ */
1395
+ async listBrowsers(args = {}) {
1396
+ return listBrowsers(this.http, args);
1397
+ }
1308
1398
  // Usage
1309
1399
  /** Current concurrency usage. */
1310
1400
  async getConcurrency() {
@@ -1345,7 +1435,7 @@ var FirecrawlClient = class {
1345
1435
  import axios2, { AxiosError } from "axios";
1346
1436
  import "zod";
1347
1437
 
1348
- // node_modules/.pnpm/typescript-event-target@1.1.1/node_modules/typescript-event-target/dist/index.mjs
1438
+ // node_modules/typescript-event-target/dist/index.mjs
1349
1439
  var e = class extends EventTarget {
1350
1440
  dispatchTypedEvent(s, t) {
1351
1441
  return super.dispatchEvent(t);
@@ -1374,7 +1464,7 @@ var FirecrawlApp = class {
1374
1464
  if (typeof process !== "undefined" && process.env && process.env.npm_package_version) {
1375
1465
  return process.env.npm_package_version;
1376
1466
  }
1377
- const packageJson = await import("./package-CMQJ5STA.js");
1467
+ const packageJson = await import("./package-BBT366VN.js");
1378
1468
  return packageJson.default.version;
1379
1469
  } catch (error) {
1380
1470
  const isTest = typeof process !== "undefined" && (process.env.JEST_WORKER_ID != null || false);
@@ -2745,7 +2835,7 @@ var Firecrawl = class extends FirecrawlClient {
2745
2835
  return this._v1;
2746
2836
  }
2747
2837
  };
2748
- var index_default = Firecrawl;
2838
+ var src_default = Firecrawl;
2749
2839
  export {
2750
2840
  Firecrawl,
2751
2841
  FirecrawlApp as FirecrawlAppV1,
@@ -2753,5 +2843,5 @@ export {
2753
2843
  JobTimeoutError,
2754
2844
  SdkError,
2755
2845
  Watcher,
2756
- index_default as default
2846
+ src_default as default
2757
2847
  };
@@ -1,4 +1,4 @@
1
1
  import {
2
2
  require_package
3
- } from "./chunk-GAAHPN3I.js";
3
+ } from "./chunk-VEC6CWSH.js";
4
4
  export default require_package();
package/dump.rdb ADDED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mendable/firecrawl-js",
3
- "version": "4.12.1",
3
+ "version": "4.13.0-beta.2",
4
4
  "description": "JavaScript SDK for Firecrawl API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/v2/client.ts CHANGED
@@ -20,6 +20,12 @@ import {
20
20
  } from "./methods/batch";
21
21
  import { startExtract, getExtractStatus, extract as extractWaiter } from "./methods/extract";
22
22
  import { startAgent, getAgentStatus, cancelAgent, agent as agentWaiter } from "./methods/agent";
23
+ import {
24
+ browser as browserMethod,
25
+ browserExecute,
26
+ deleteBrowser,
27
+ listBrowsers,
28
+ } from "./methods/browser";
23
29
  import { getConcurrency, getCreditUsage, getQueueStatus, getTokenUsage, getCreditUsageHistorical, getTokenUsageHistorical } from "./methods/usage";
24
30
  import type {
25
31
  Document,
@@ -40,6 +46,10 @@ import type {
40
46
  CrawlOptions,
41
47
  BatchScrapeOptions,
42
48
  PaginationConfig,
49
+ BrowserCreateResponse,
50
+ BrowserExecuteResponse,
51
+ BrowserDeleteResponse,
52
+ BrowserListResponse,
43
53
  } from "./types";
44
54
  import { Watcher } from "./watcher";
45
55
  import type { WatcherOptions } from "./watcher";
@@ -298,6 +308,47 @@ export class FirecrawlClient {
298
308
  return cancelAgent(this.http, jobId);
299
309
  }
300
310
 
311
+ // Browser
312
+ /**
313
+ * Create a new browser session.
314
+ * @param args Session options (ttlTotal, ttlWithoutActivity, streamWebView).
315
+ * @returns Session id and CDP URL.
316
+ */
317
+ async browser(
318
+ args: Parameters<typeof browserMethod>[1] = {}
319
+ ): Promise<BrowserCreateResponse> {
320
+ return browserMethod(this.http, args);
321
+ }
322
+ /**
323
+ * Execute code in a browser session.
324
+ * @param sessionId Browser session id.
325
+ * @param args Code and language to execute.
326
+ * @returns Execution result.
327
+ */
328
+ async browserExecute(
329
+ sessionId: string,
330
+ args: Parameters<typeof browserExecute>[2]
331
+ ): Promise<BrowserExecuteResponse> {
332
+ return browserExecute(this.http, sessionId, args);
333
+ }
334
+ /**
335
+ * Delete a browser session.
336
+ * @param sessionId Browser session id.
337
+ */
338
+ async deleteBrowser(sessionId: string): Promise<BrowserDeleteResponse> {
339
+ return deleteBrowser(this.http, sessionId);
340
+ }
341
+ /**
342
+ * List browser sessions.
343
+ * @param args Optional filter (status: "active" | "destroyed").
344
+ * @returns List of browser sessions.
345
+ */
346
+ async listBrowsers(
347
+ args: Parameters<typeof listBrowsers>[1] = {}
348
+ ): Promise<BrowserListResponse> {
349
+ return listBrowsers(this.http, args);
350
+ }
351
+
301
352
  // Usage
302
353
  /** Current concurrency usage. */
303
354
  async getConcurrency() {
@@ -0,0 +1,92 @@
1
+ import type {
2
+ BrowserCreateResponse,
3
+ BrowserExecuteResponse,
4
+ BrowserDeleteResponse,
5
+ BrowserListResponse,
6
+ } from "../types";
7
+ import { HttpClient } from "../utils/httpClient";
8
+ import { normalizeAxiosError, throwForBadResponse } from "../utils/errorHandler";
9
+
10
+ export async function browser(
11
+ http: HttpClient,
12
+ args: {
13
+ ttlTotal?: number;
14
+ ttlWithoutActivity?: number;
15
+ streamWebView?: boolean;
16
+ } = {}
17
+ ): Promise<BrowserCreateResponse> {
18
+ const body: Record<string, unknown> = {};
19
+ if (args.ttlTotal != null) body.ttlTotal = args.ttlTotal;
20
+ if (args.ttlWithoutActivity != null) body.ttlWithoutActivity = args.ttlWithoutActivity;
21
+ if (args.streamWebView != null) body.streamWebView = args.streamWebView;
22
+
23
+ try {
24
+ const res = await http.post<BrowserCreateResponse>("/v2/browser", body);
25
+ if (res.status !== 200) throwForBadResponse(res, "create browser session");
26
+ return res.data;
27
+ } catch (err: any) {
28
+ if (err?.isAxiosError) return normalizeAxiosError(err, "create browser session");
29
+ throw err;
30
+ }
31
+ }
32
+
33
+ export async function browserExecute(
34
+ http: HttpClient,
35
+ sessionId: string,
36
+ args: {
37
+ code: string;
38
+ language?: "python" | "js";
39
+ }
40
+ ): Promise<BrowserExecuteResponse> {
41
+ const body: Record<string, unknown> = {
42
+ code: args.code,
43
+ language: args.language ?? "python",
44
+ };
45
+
46
+ try {
47
+ const res = await http.post<BrowserExecuteResponse>(
48
+ `/v2/browser/${sessionId}/execute`,
49
+ body
50
+ );
51
+ if (res.status !== 200) throwForBadResponse(res, "execute browser code");
52
+ return res.data;
53
+ } catch (err: any) {
54
+ if (err?.isAxiosError) return normalizeAxiosError(err, "execute browser code");
55
+ throw err;
56
+ }
57
+ }
58
+
59
+ export async function deleteBrowser(
60
+ http: HttpClient,
61
+ sessionId: string
62
+ ): Promise<BrowserDeleteResponse> {
63
+ try {
64
+ const res = await http.delete<BrowserDeleteResponse>(
65
+ `/v2/browser/${sessionId}`
66
+ );
67
+ if (res.status !== 200) throwForBadResponse(res, "delete browser session");
68
+ return res.data;
69
+ } catch (err: any) {
70
+ if (err?.isAxiosError) return normalizeAxiosError(err, "delete browser session");
71
+ throw err;
72
+ }
73
+ }
74
+
75
+ export async function listBrowsers(
76
+ http: HttpClient,
77
+ args: {
78
+ status?: "active" | "destroyed";
79
+ } = {}
80
+ ): Promise<BrowserListResponse> {
81
+ let endpoint = "/v2/browser";
82
+ if (args.status) endpoint += `?status=${args.status}`;
83
+
84
+ try {
85
+ const res = await http.get<BrowserListResponse>(endpoint);
86
+ if (res.status !== 200) throwForBadResponse(res, "list browser sessions");
87
+ return res.data;
88
+ } catch (err: any) {
89
+ if (err?.isAxiosError) return normalizeAxiosError(err, "list browser sessions");
90
+ throw err;
91
+ }
92
+ }
package/src/v2/types.ts CHANGED
@@ -683,3 +683,39 @@ export interface QueueStatusResponse {
683
683
  maxConcurrency: number;
684
684
  mostRecentSuccess: string | null;
685
685
  }
686
+
687
+ // Browser types
688
+ export interface BrowserCreateResponse {
689
+ success: boolean;
690
+ id?: string;
691
+ cdpUrl?: string;
692
+ liveViewUrl?: string;
693
+ error?: string;
694
+ }
695
+
696
+ export interface BrowserExecuteResponse {
697
+ success: boolean;
698
+ result?: string;
699
+ error?: string;
700
+ }
701
+
702
+ export interface BrowserDeleteResponse {
703
+ success: boolean;
704
+ error?: string;
705
+ }
706
+
707
+ export interface BrowserSession {
708
+ id: string;
709
+ status: string;
710
+ cdpUrl: string;
711
+ liveViewUrl: string;
712
+ streamWebView: boolean;
713
+ createdAt: string;
714
+ lastActivity: string;
715
+ }
716
+
717
+ export interface BrowserListResponse {
718
+ success: boolean;
719
+ sessions?: BrowserSession[];
720
+ error?: string;
721
+ }