Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { describe, expect, jest, test } from "@jest/globals";
import { browser } from "../../../v2/methods/browser";

function httpMock() {
return {
post: jest.fn(
async () => ({ status: 200, data: { success: true, id: "sess_123" } }),
),
} as any;
}

describe("v2 browser recordSession", () => {
test("forwards recordSession: false so session recording can be disabled", async () => {
const http = httpMock();

await browser(http, { recordSession: false });

expect(http.post).toHaveBeenCalledWith(
"/v2/browser",
{ recordSession: false },
);
});

test("omits recordSession when the caller does not set it (server default applies)", async () => {
const http = httpMock();

await browser(http, { ttl: 600 });

expect(http.post).toHaveBeenCalledWith("/v2/browser", { ttl: 600 });
const payload = http.post.mock.calls[0][1] as Record<string, unknown>;
expect(payload).not.toHaveProperty("recordSession");
});
});
2 changes: 1 addition & 1 deletion apps/js-sdk/firecrawl/src/v2/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ export class FirecrawlClient {
// Browser
/**
* Create a new browser session.
* @param args Session options (ttl, activityTtl, streamWebView, profile).
* @param args Session options (ttl, activityTtl, streamWebView, recordSession, profile).
* @returns Session id, CDP URL, live view URL, and expiration time.
*/
async browser(
Expand Down
2 changes: 2 additions & 0 deletions apps/js-sdk/firecrawl/src/v2/methods/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export async function browser(
ttl?: number;
activityTtl?: number;
streamWebView?: boolean;
recordSession?: boolean;
profile?: {
name: string;
saveChanges?: boolean;
Expand All @@ -28,6 +29,7 @@ export async function browser(
if (args.ttl != null) body.ttl = args.ttl;
if (args.activityTtl != null) body.activityTtl = args.activityTtl;
if (args.streamWebView != null) body.streamWebView = args.streamWebView;
if (args.recordSession != null) body.recordSession = args.recordSession;
if (args.profile != null) body.profile = args.profile;
if (args.integration != null) body.integration = args.integration;
if (args.origin) body.origin = args.origin;
Expand Down
3 changes: 3 additions & 0 deletions apps/python-sdk/firecrawl/v2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1617,6 +1617,7 @@ def browser(
ttl: Optional[int] = None,
activity_ttl: Optional[int] = None,
stream_web_view: Optional[bool] = None,
record_session: Optional[bool] = None,
profile: Optional[Dict[str, Any]] = None,
):
"""Create a new browser session.
Expand All @@ -1625,6 +1626,7 @@ def browser(
ttl: Total time-to-live in seconds (30-3600, default 300)
activity_ttl: Inactivity TTL in seconds (10-3600)
stream_web_view: Whether to enable webview streaming
record_session: Whether to record the session (default True server-side)
profile: Profile config with ``name`` (str) and
optional ``save_changes`` (bool, default ``True``)

Expand All @@ -1636,6 +1638,7 @@ def browser(
ttl=ttl,
activity_ttl=activity_ttl,
stream_web_view=stream_web_view,
record_session=record_session,
profile=profile,
)

Expand Down
3 changes: 3 additions & 0 deletions apps/python-sdk/firecrawl/v2/client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,7 @@ async def browser(
ttl: Optional[int] = None,
activity_ttl: Optional[int] = None,
stream_web_view: Optional[bool] = None,
record_session: Optional[bool] = None,
profile: Optional[Dict[str, Any]] = None,
):
"""Create a new browser session.
Expand All @@ -890,6 +891,7 @@ async def browser(
ttl: Total time-to-live in seconds (30-3600, default 300)
activity_ttl: Inactivity TTL in seconds (10-3600)
stream_web_view: Whether to enable webview streaming
record_session: Whether to record the session (default True server-side)
profile: Profile config with ``name`` (str) and
optional ``save_changes`` (bool, default ``True``)

Expand All @@ -901,6 +903,7 @@ async def browser(
ttl=ttl,
activity_ttl=activity_ttl,
stream_web_view=stream_web_view,
record_session=record_session,
profile=profile,
)

Expand Down
4 changes: 4 additions & 0 deletions apps/python-sdk/firecrawl/v2/methods/aio/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ async def browser(
ttl: Optional[int] = None,
activity_ttl: Optional[int] = None,
stream_web_view: Optional[bool] = None,
record_session: Optional[bool] = None,
profile: Optional[Dict[str, Any]] = None,
) -> BrowserCreateResponse:
"""Create a new browser session.
Expand All @@ -66,6 +67,7 @@ async def browser(
ttl: Total time-to-live in seconds (30-3600, default 300)
activity_ttl: Inactivity TTL in seconds (10-3600)
stream_web_view: Whether to enable webview streaming
record_session: Whether to record the session (default True server-side)
profile: Profile config with ``name`` (str) and
optional ``save_changes`` (bool, default ``True``)

Expand All @@ -79,6 +81,8 @@ async def browser(
body["activityTtl"] = activity_ttl
if stream_web_view is not None:
body["streamWebView"] = stream_web_view
if record_session is not None:
body["recordSession"] = record_session
if profile is not None:
body["profile"] = {
"name": profile["name"],
Expand Down
4 changes: 4 additions & 0 deletions apps/python-sdk/firecrawl/v2/methods/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def browser(
ttl: Optional[int] = None,
activity_ttl: Optional[int] = None,
stream_web_view: Optional[bool] = None,
record_session: Optional[bool] = None,
profile: Optional[Dict[str, Any]] = None,
) -> BrowserCreateResponse:
"""Create a new browser session.
Expand All @@ -67,6 +68,7 @@ def browser(
ttl: Total time-to-live in seconds (30-3600, default 300)
activity_ttl: Inactivity TTL in seconds (10-3600)
stream_web_view: Whether to enable webview streaming
record_session: Whether to record the session (default True server-side)
profile: Profile config with ``name`` (str) and
optional ``save_changes`` (bool, default ``True``)

Expand All @@ -80,6 +82,8 @@ def browser(
body["activityTtl"] = activity_ttl
if stream_web_view is not None:
body["streamWebView"] = stream_web_view
if record_session is not None:
body["recordSession"] = record_session
if profile is not None:
body["profile"] = {
"name": profile["name"],
Expand Down
53 changes: 53 additions & 0 deletions apps/python-sdk/tests/test_browser_record_session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""v2 browser.create should forward record_session (opt-out of session recording)."""
import unittest
from unittest.mock import MagicMock, patch

from firecrawl.v2.client import FirecrawlClient
from firecrawl.v2.methods import browser as browser_module


def _ok_response(payload):
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.ok = True
mock_response.json.return_value = {"success": True, **payload}
return mock_response


class TestBrowserRecordSession(unittest.TestCase):
def _client(self):
return FirecrawlClient(api_key="dummy-api-key-for-testing")

@patch("requests.post")
def test_browser_forwards_record_session_false(self, mock_post):
mock_post.return_value = _ok_response({"id": "sess_123"})
client = self._client()

client.browser(record_session=False)

_, kwargs = mock_post.call_args
self.assertIn("recordSession", kwargs["json"])
self.assertIs(kwargs["json"]["recordSession"], False)

@patch("requests.post")
def test_browser_omits_record_session_by_default(self, mock_post):
mock_post.return_value = _ok_response({"id": "sess_123"})
client = self._client()

client.browser(ttl=600)

_, kwargs = mock_post.call_args
self.assertNotIn("recordSession", kwargs["json"])

def test_browser_module_forwards_record_session_false(self):
client = MagicMock()
client.post.return_value = _ok_response({"id": "sess_123"})

browser_module.browser(client, record_session=False)

sent_body = client.post.call_args[0][1]
self.assertIs(sent_body.get("recordSession"), False)


if __name__ == "__main__":
unittest.main()