Skip to content
Merged
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
6 changes: 6 additions & 0 deletions hyperbrowser/models/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ class SessionLaunchState(BaseModel):
disable_post_quantum_key_agreement: Optional[bool] = Field(
default=None, alias="disablePostQuantumKeyAgreement"
)
disable_software_webgl: Optional[bool] = Field(
default=None, alias="disableSoftwareWebGL"
)
enable_webgl_fingerprinting: Optional[bool] = Field(
default=None, alias="enableWebglFingerprinting"
)
Expand Down Expand Up @@ -664,6 +667,9 @@ class CreateSessionParams(BaseModel):
disable_post_quantum_key_agreement: Optional[bool] = Field(
default=None, serialization_alias="disablePostQuantumKeyAgreement"
)
disable_software_webgl: Optional[bool] = Field(
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
default=None, serialization_alias="disableSoftwareWebGL"
)
enable_webgl_fingerprinting: Optional[bool] = Field(
default=None, serialization_alias="enableWebglFingerprinting"
)
Expand Down
7 changes: 7 additions & 0 deletions hyperbrowser/models/web/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Country,
State,
FetchSanitizeMode,
OperatingSystem,
)
from hyperbrowser.models.session import ScreenConfig
from hyperbrowser.models.web.branding import BrandingProfile
Expand Down Expand Up @@ -166,6 +167,12 @@ class FetchBrowserOptions(BaseModel):
location: Optional[FetchBrowserLocationOptions] = Field(
default=None, serialization_alias="location"
)
operating_system: Optional[OperatingSystem] = Field(
default=None, serialization_alias="operatingSystem"
)
disable_software_webgl: Optional[bool] = Field(
default=None, serialization_alias="disableSoftwareWebGL"
)


class FetchNavigationOptions(BaseModel):
Expand Down
1 change: 1 addition & 0 deletions hyperbrowser/types/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class CreateSessionParams(TypedDict, total=False):
live_view_ttl_seconds: Optional[int]
replace_native_elements: Optional[bool]
disable_post_quantum_key_agreement: Optional[bool]
disable_software_webgl: Optional[bool]
enable_webgl_fingerprinting: Optional[bool] # Deprecated: ignored by the server
browser_memory_size: Optional[BrowserMemorySize]
start_from_snapshot: Optional[StartSessionFromSnapshotParams]
Expand Down
3 changes: 3 additions & 0 deletions hyperbrowser/types/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
FetchScreenshotFormat,
FetchStealthMode,
FetchWaitUntil,
OperatingSystem,
State,
)
from hyperbrowser.models.web.search import WebSearchFiletype
Expand Down Expand Up @@ -112,6 +113,8 @@ class FetchBrowserOptions(TypedDict, total=False):
profile_id: Optional[str]
solve_captchas: Optional[bool]
location: Optional[FetchBrowserLocationOptions]
operating_system: Optional[OperatingSystem]
disable_software_webgl: Optional[bool]


class FetchNavigationOptions(TypedDict, total=False):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "hyperbrowser"
version = "1.15.6"
version = "1.15.7"
description = "Python SDK for hyperbrowser"
authors = ["Nikhil Shahi <nshahi1998@gmail.com>"]
license = "MIT"
Expand Down
59 changes: 59 additions & 0 deletions tests/test_request_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,20 @@
CuaBaseUrls,
CreateSandboxParams,
CreateSessionParams,
FetchBrowserOptions,
FetchParams,
GeminiComputerUseApiKeys,
JevComputerUseApiKeys,
MetaComputerUseApiKeys,
SessionLaunchState,
StartBatchFetchJobParams,
StartBrowserUseTaskParams,
StartClaudeComputerUseTaskParams,
StartCuaTaskParams,
StartGeminiComputerUseTaskParams,
StartJevComputerUseTaskParams,
StartMetaComputerUseTaskParams,
StartWebCrawlJobParams,
)
from hyperbrowser.tools import _normalize_extract_tool_params

Expand Down Expand Up @@ -313,3 +318,57 @@ def test_extract_tool_schema_string_is_parsed_without_mutating_input():
"type": "object",
"properties": {"snake_case": {"type": "string"}},
}


def test_session_disable_software_webgl_serializes_for_mapping_and_legacy_model():
mapping = {"disable_software_webgl": True}
legacy = CreateSessionParams(**mapping)

assert dump_request(mapping, CreateSessionParams) == dump_request(
legacy, CreateSessionParams
)
assert dump_request(mapping, CreateSessionParams)["disableSoftwareWebGL"] is True
assert (
dump_request({"disable_software_webgl": False}, CreateSessionParams)[
"disableSoftwareWebGL"
]
is False
)
assert "disableSoftwareWebGL" not in dump_request({}, CreateSessionParams)


@pytest.mark.parametrize(
("model", "base"),
[
(FetchParams, {"url": "https://example.com"}),
(StartBatchFetchJobParams, {"urls": ["https://example.com"]}),
(StartWebCrawlJobParams, {"url": "https://example.com"}),
],
)
def test_fetch_browser_operating_system_and_webgl_serialize_for_mapping_and_legacy_model(
model, base
):
browser = {"operating_system": "macos", "disable_software_webgl": True}
mapping = {**base, "browser": browser}
legacy = model(**base, browser=FetchBrowserOptions(**browser))

expected = {"operatingSystem": "macos", "disableSoftwareWebGL": True}
assert dump_request(mapping, model)["browser"] == expected
assert dump_request(legacy, model)["browser"] == expected
assert "browser" not in dump_request(base, model)
assert dump_request({**base, "browser": {"operating_system": "ios"}}, model)[
"browser"
] == {"operatingSystem": "ios"}


def test_fetch_browser_operating_system_rejects_unknown_values():
with pytest.raises(ValidationError):
FetchBrowserOptions(operating_system="beos")


def test_session_launch_state_parses_disable_software_webgl():
assert (
SessionLaunchState(**{"disableSoftwareWebGL": True}).disable_software_webgl
is True
)
assert SessionLaunchState().disable_software_webgl is None
12 changes: 12 additions & 0 deletions tests/typecheck/invalid_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ def invalid_sync_requests(client: Hyperbrowser) -> None:
"outputs": {"formats": [{"type": "xml"}]}, # M
}
)
client.web.fetch(
{ # P
"url": "https://example.com",
"browser": {"operating_system": "beos"}, # M
}
)
client.web.fetch(
{ # P
"url": "https://example.com",
"browser": {"disable_software_webgl": "yes"}, # M
}
)
client.sandboxes.create({"image_name": "node", "cpu": "four"}) # M,P
client.secrets.create({"description": "missing name"}) # M,P
client.sandboxes.create({"image_name": "node", "secrets": {"A": 1}}) # M,P
Expand Down
3 changes: 3 additions & 0 deletions tests/typecheck/valid_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def valid_sync_requests(client: Hyperbrowser) -> None:
client.sessions.create(
{
"use_stealth": True,
"disable_software_webgl": True,
"region": "us",
"screen": {"width": 1440, "height": 900},
"profile": {
Expand Down Expand Up @@ -69,6 +70,8 @@ def valid_sync_requests(client: Hyperbrowser) -> None:
"browser": {
"screen": {"width": 1280, "height": 720},
"location": {"country": "US", "state": "CA"},
"operating_system": "macos",
"disable_software_webgl": True,
},
}
)
Expand Down