stagehand 4.3.0a0.dev1620__tar.gz → 4.3.0a0.dev1624__tar.gz
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.
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/PKG-INFO +1 -1
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/pyproject.toml +1 -1
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/_extension/service-worker.js +14 -2
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/_generated/protocol_version.py +1 -1
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/_validation.py +61 -2
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/browser.py +9 -0
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/cdp_client.py +98 -10
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/client_models.py +5 -2
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/client_types.py +2 -0
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/README.md +0 -0
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/__init__.py +0 -0
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/_extension/blank.html +0 -0
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/_extension/content-script.js +0 -0
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/_extension/manifest.json +0 -0
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/_extension/offscreen/service-worker-heartbeat.html +0 -0
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/_extension/offscreen/service-worker-heartbeat.js +0 -0
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/_extension/wake-service-worker.html +0 -0
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/_extension/wake-service-worker.js +0 -0
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/_generated/__init__.py +0 -0
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/_generated/input_types.py +0 -0
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/_generated/models.py +0 -0
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/_sdk_identity.py +0 -0
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/browser_clipboard.py +0 -0
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/browser_context.py +0 -0
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/browserbase_connection.py +0 -0
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/browserbase_rpc.py +0 -0
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/browserbase_services.py +0 -0
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/browserbase_session.py +0 -0
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/browserbase_transport.py +0 -0
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/extension_assets.py +0 -0
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/file_upload.py +0 -0
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/locator.py +0 -0
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/page.py +0 -0
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/py.typed +0 -0
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/response.py +0 -0
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/rpc_client.py +0 -0
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/stagehand.py +0 -0
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/timeouts.py +0 -0
- {stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/webmcp.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: stagehand
|
|
3
|
-
Version: 4.3.0a0.
|
|
3
|
+
Version: 4.3.0a0.dev1624
|
|
4
4
|
Summary: Browserbase's SDK for building browser agents
|
|
5
5
|
Keywords: ai,agent,ai-agent,browser,browser-agent,browser-automation,computer-use,headless,playwright,cdp,llm,automation,web-scraping,testing
|
|
6
6
|
Author: Browserbase
|
{stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/_extension/service-worker.js
RENAMED
|
@@ -7363,7 +7363,7 @@ function isRecord$1(value) {
|
|
|
7363
7363
|
}
|
|
7364
7364
|
var package_default$1 = {
|
|
7365
7365
|
name: "@browserbasehq/stagehand-protocol",
|
|
7366
|
-
version: "3.0.0-alpha-
|
|
7366
|
+
version: "3.0.0-alpha-77170ed9f8252581458360ab511c55a4be31fb44",
|
|
7367
7367
|
"private": true,
|
|
7368
7368
|
type: "module",
|
|
7369
7369
|
exports: {
|
|
@@ -12527,8 +12527,20 @@ strictObject({
|
|
|
12527
12527
|
acceptDownloads: boolean().optional(),
|
|
12528
12528
|
keepAlive: boolean().optional()
|
|
12529
12529
|
}).meta({ id: "LocalBrowserLaunchOptions" });
|
|
12530
|
+
var CDPHeadersSchema = preprocess((value) => {
|
|
12531
|
+
try {
|
|
12532
|
+
if (typeof value !== "object" || value === null || Array.isArray(value) || ![Object.prototype, null].includes(Object.getPrototypeOf(value))) return null;
|
|
12533
|
+
const entries = Object.entries(value);
|
|
12534
|
+
if (!entries.every(([name, content]) => name.length > 0 && !/[^!#$%&'*+\-.^_`|~0-9A-Za-z]/.test(name) && typeof content === "string" && !/[^\t\x20-\x7e]/.test(content) && content === content.replace(/^[ \t]+|[ \t]+$/g, ""))) return null;
|
|
12535
|
+
return Object.fromEntries(entries);
|
|
12536
|
+
} catch {
|
|
12537
|
+
return null;
|
|
12538
|
+
}
|
|
12539
|
+
}, record(string(), string(), { error: "headers must map valid HTTP header names to ASCII string values without leading or trailing spaces or tabs" }));
|
|
12530
12540
|
strictObject({
|
|
12531
12541
|
cdpUrl: string().min(1),
|
|
12542
|
+
/** Headers for client-side CDP discovery and WebSocket connections. */
|
|
12543
|
+
headers: CDPHeadersSchema.optional(),
|
|
12532
12544
|
extensionId: string().optional(),
|
|
12533
12545
|
/**
|
|
12534
12546
|
* Browser-level CDP WebSocket URL dialed by the extension inside Chrome.
|
|
@@ -54471,7 +54483,7 @@ var WebTracerProvider = class extends BasicTracerProvider {
|
|
|
54471
54483
|
};
|
|
54472
54484
|
var package_default = {
|
|
54473
54485
|
name: "@browserbasehq/stagehand-extension",
|
|
54474
|
-
version: "1.2.0-alpha-
|
|
54486
|
+
version: "1.2.0-alpha-77170ed9f8252581458360ab511c55a4be31fb44",
|
|
54475
54487
|
"private": true,
|
|
54476
54488
|
type: "module",
|
|
54477
54489
|
scripts: {
|
{stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/_generated/protocol_version.py
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
"""Generated from packages/protocol/package.json. Do not edit."""
|
|
2
2
|
|
|
3
3
|
PROTOCOL_SEMVER_PATTERN = '^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[A-Za-z-][0-9A-Za-z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\\+([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?$'
|
|
4
|
-
STAGEHAND_PROTOCOL_VERSION = '3.0.0-alpha-
|
|
4
|
+
STAGEHAND_PROTOCOL_VERSION = '3.0.0-alpha-77170ed9f8252581458360ab511c55a4be31fb44'
|
|
@@ -1,8 +1,19 @@
|
|
|
1
|
+
import re
|
|
1
2
|
from collections.abc import Mapping
|
|
2
|
-
from typing import Annotated
|
|
3
|
+
from typing import Annotated, cast
|
|
3
4
|
from urllib.parse import urlparse
|
|
4
5
|
|
|
5
|
-
from pydantic import
|
|
6
|
+
from pydantic import (
|
|
7
|
+
AfterValidator,
|
|
8
|
+
AnyUrl,
|
|
9
|
+
BaseModel,
|
|
10
|
+
ConfigDict,
|
|
11
|
+
TypeAdapter,
|
|
12
|
+
ValidationError,
|
|
13
|
+
ValidatorFunctionWrapHandler,
|
|
14
|
+
WrapValidator,
|
|
15
|
+
model_validator,
|
|
16
|
+
)
|
|
6
17
|
from typing_extensions import override
|
|
7
18
|
|
|
8
19
|
_url_adapter = TypeAdapter(AnyUrl)
|
|
@@ -15,6 +26,54 @@ def _validate_url(value: str) -> str:
|
|
|
15
26
|
|
|
16
27
|
WireUrl = Annotated[str, AfterValidator(_validate_url)]
|
|
17
28
|
|
|
29
|
+
# RFC 9110 field names are tokens. Restrict values to ASCII so HTTP discovery
|
|
30
|
+
# and WebSocket handshakes encode them identically; allow only internal whitespace.
|
|
31
|
+
_HEADER_NAME = re.compile(r"[!#$%&'*+\-.^_`|~0-9A-Za-z]+")
|
|
32
|
+
_HEADER_VALUE = re.compile(r"[\t\x20-\x7e]*")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _validate_headers(value: Mapping[str, str]) -> Mapping[str, str]:
|
|
36
|
+
for name, header_value in value.items():
|
|
37
|
+
if not _HEADER_NAME.fullmatch(name):
|
|
38
|
+
raise ValueError
|
|
39
|
+
if not _HEADER_VALUE.fullmatch(header_value) or header_value != header_value.strip(" \t"):
|
|
40
|
+
raise ValueError
|
|
41
|
+
return value
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _redact_header_validation_errors(
|
|
45
|
+
value: object, handler: ValidatorFunctionWrapHandler
|
|
46
|
+
) -> dict[str, str]:
|
|
47
|
+
try:
|
|
48
|
+
return cast(dict[str, str], handler(value))
|
|
49
|
+
except ValidationError:
|
|
50
|
+
# Error inputs, locations, and validator context can all contain credentials.
|
|
51
|
+
# Rebuild the error rather than only hiding inputs in its formatted message.
|
|
52
|
+
raise ValidationError.from_exception_data(
|
|
53
|
+
"CDP headers",
|
|
54
|
+
[
|
|
55
|
+
{
|
|
56
|
+
"type": "value_error",
|
|
57
|
+
"loc": (),
|
|
58
|
+
"input": "[redacted]",
|
|
59
|
+
"ctx": {
|
|
60
|
+
"error": ValueError(
|
|
61
|
+
"headers must map valid HTTP header names to ASCII string values "
|
|
62
|
+
"without leading or trailing spaces or tabs"
|
|
63
|
+
)
|
|
64
|
+
},
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
hide_input=True,
|
|
68
|
+
) from None
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
WireHeaders = Annotated[
|
|
72
|
+
dict[str, str],
|
|
73
|
+
AfterValidator(_validate_headers),
|
|
74
|
+
WrapValidator(_redact_header_validation_errors),
|
|
75
|
+
]
|
|
76
|
+
|
|
18
77
|
|
|
19
78
|
def _validate_websocket_url(value: str) -> str:
|
|
20
79
|
parsed = urlparse(value)
|
|
@@ -312,12 +312,14 @@ async def _connect_browser(
|
|
|
312
312
|
preloaded_extension: bool = False,
|
|
313
313
|
after_connect: Callable[[CDPClient], Awaitable[None]] | None = None,
|
|
314
314
|
worker_init_metadata: _WorkerInitMetadata,
|
|
315
|
+
headers: Mapping[str, str] | None = None,
|
|
315
316
|
) -> StagehandBrowser:
|
|
316
317
|
owns_source = origin == "launched" and not source.keep_alive
|
|
317
318
|
cdp_client: CDPClient | None = None
|
|
318
319
|
try:
|
|
319
320
|
cdp_client = await CDPClient.connect(
|
|
320
321
|
cdp_url=source.cdp_url,
|
|
322
|
+
**({"headers": headers} if headers else {}),
|
|
321
323
|
extension_dir=extension_dir,
|
|
322
324
|
local_extension_dir=local_extension_dir,
|
|
323
325
|
extension_id=extension_id,
|
|
@@ -536,6 +538,7 @@ class LocalBrowser:
|
|
|
536
538
|
cdp_url: str,
|
|
537
539
|
extension_id: str | None = None,
|
|
538
540
|
extension_cdp_url: str | None = None,
|
|
541
|
+
headers: Mapping[str, str] | None = None,
|
|
539
542
|
) -> StagehandBrowser:
|
|
540
543
|
"""Connect to an existing browser.
|
|
541
544
|
|
|
@@ -547,6 +550,10 @@ class LocalBrowser:
|
|
|
547
550
|
client connected to. Set it when the client reaches Chrome through
|
|
548
551
|
a proxy the browser cannot or should not use, such as an
|
|
549
552
|
authenticated gateway whose URL carries credentials.
|
|
553
|
+
headers: HTTP headers to send with the CDP connection, such as a
|
|
554
|
+
gateway's credentials, so they need not ride in `cdp_url`. They
|
|
555
|
+
go to `cdp_url` and to the WebSocket it advertises when that is
|
|
556
|
+
on the same host, never elsewhere, and never to the extension.
|
|
550
557
|
"""
|
|
551
558
|
options = LocalBrowserConnectOptions.model_validate({
|
|
552
559
|
name: value
|
|
@@ -554,6 +561,7 @@ class LocalBrowser:
|
|
|
554
561
|
("cdp_url", cdp_url),
|
|
555
562
|
("extension_id", extension_id),
|
|
556
563
|
("extension_cdp_url", extension_cdp_url),
|
|
564
|
+
("headers", dict(headers) if isinstance(headers, Mapping) else headers),
|
|
557
565
|
)
|
|
558
566
|
if value is not None
|
|
559
567
|
})
|
|
@@ -567,6 +575,7 @@ class LocalBrowser:
|
|
|
567
575
|
browser=None,
|
|
568
576
|
browser_cdp_url=options.extension_cdp_url,
|
|
569
577
|
),
|
|
578
|
+
headers=options.headers,
|
|
570
579
|
)
|
|
571
580
|
|
|
572
581
|
|
|
@@ -2,19 +2,28 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import asyncio
|
|
4
4
|
import json
|
|
5
|
+
import logging
|
|
5
6
|
import re
|
|
6
7
|
import time
|
|
7
8
|
from collections.abc import Callable, Mapping
|
|
8
9
|
from contextlib import suppress
|
|
9
10
|
from dataclasses import dataclass
|
|
10
11
|
from typing import Any, Literal, Protocol, cast
|
|
11
|
-
from urllib.
|
|
12
|
+
from urllib.error import HTTPError
|
|
13
|
+
from urllib.parse import urljoin, urlsplit
|
|
14
|
+
from urllib.request import HTTPRedirectHandler, Request, build_opener, urlopen
|
|
15
|
+
|
|
16
|
+
from typing_extensions import override
|
|
17
|
+
from websockets.asyncio.client import connect as WebSocketConnect
|
|
18
|
+
from websockets.exceptions import InvalidStatus
|
|
12
19
|
|
|
13
20
|
from stagehand._generated.protocol_version import (
|
|
14
21
|
PROTOCOL_SEMVER_PATTERN,
|
|
15
22
|
STAGEHAND_PROTOCOL_VERSION,
|
|
16
23
|
)
|
|
17
24
|
|
|
25
|
+
_LOGGER = logging.getLogger(__name__)
|
|
26
|
+
|
|
18
27
|
STAGEHAND_SEND_TO_HOST_BINDING = "__stagehandSendToHost"
|
|
19
28
|
_RUNTIME_NAME = "stagehand"
|
|
20
29
|
_STAGEHAND_EXTENSION_NAME = "Stagehand Runtime"
|
|
@@ -257,6 +266,7 @@ class CDPClient:
|
|
|
257
266
|
extension_id: str | None = None,
|
|
258
267
|
preloaded_extension: bool = False,
|
|
259
268
|
service_worker_url_includes: str | None = None,
|
|
269
|
+
headers: Mapping[str, str] | None = None,
|
|
260
270
|
) -> CDPClient:
|
|
261
271
|
"""Connect without an independent lifecycle deadline.
|
|
262
272
|
|
|
@@ -278,8 +288,16 @@ class CDPClient:
|
|
|
278
288
|
"or preloaded_extension is required"
|
|
279
289
|
)
|
|
280
290
|
|
|
281
|
-
web_socket_debugger_url = await _resolve_browser_web_socket_url(cdp_url)
|
|
282
|
-
|
|
291
|
+
web_socket_debugger_url = await _resolve_browser_web_socket_url(cdp_url, headers=headers)
|
|
292
|
+
web_socket_headers = headers or None
|
|
293
|
+
if web_socket_headers and not _can_forward_headers(cdp_url, web_socket_debugger_url):
|
|
294
|
+
web_socket_headers = None
|
|
295
|
+
_LOGGER.debug(
|
|
296
|
+
"CDP headers were withheld from the advertised WebSocket endpoint because "
|
|
297
|
+
"its host or port differs, or forwarding would downgrade transport security. "
|
|
298
|
+
"If the handshake is rejected, check the gateway's advertised CDP endpoint."
|
|
299
|
+
)
|
|
300
|
+
socket = await _connect_web_socket(web_socket_debugger_url, headers=web_socket_headers)
|
|
283
301
|
client = cls(socket, web_socket_debugger_url)
|
|
284
302
|
|
|
285
303
|
try:
|
|
@@ -659,33 +677,103 @@ class CDPClient:
|
|
|
659
677
|
task.add_done_callback(finish)
|
|
660
678
|
|
|
661
679
|
|
|
662
|
-
|
|
663
|
-
|
|
680
|
+
class _UnsafeCDPRedirectError(RuntimeError):
|
|
681
|
+
"""A redirect would expose caller headers to an unauthorized endpoint."""
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
_DEFAULT_PORTS = {"http": 80, "ws": 80, "https": 443, "wss": 443}
|
|
685
|
+
|
|
686
|
+
|
|
687
|
+
def _can_forward_headers(source: str, destination: str) -> bool:
|
|
688
|
+
"""Require the same host and effective port, without a TLS downgrade."""
|
|
689
|
+
try:
|
|
690
|
+
first, second = urlsplit(source), urlsplit(destination)
|
|
691
|
+
return (
|
|
692
|
+
first.scheme in _DEFAULT_PORTS
|
|
693
|
+
and second.scheme in _DEFAULT_PORTS
|
|
694
|
+
and first.hostname is not None
|
|
695
|
+
and first.hostname == second.hostname
|
|
696
|
+
and (first.port if first.port is not None else _DEFAULT_PORTS[first.scheme])
|
|
697
|
+
== (second.port if second.port is not None else _DEFAULT_PORTS[second.scheme])
|
|
698
|
+
and not (first.scheme in ("https", "wss") and second.scheme in ("http", "ws"))
|
|
699
|
+
)
|
|
700
|
+
except ValueError:
|
|
701
|
+
return False
|
|
702
|
+
|
|
703
|
+
|
|
704
|
+
class _CDPRedirectHandler(HTTPRedirectHandler):
|
|
705
|
+
@override
|
|
706
|
+
def redirect_request(
|
|
707
|
+
self, req: Request, fp: Any, code: int, msg: str, headers: Any, newurl: str
|
|
708
|
+
) -> Request | None:
|
|
709
|
+
if not _can_forward_headers(req.full_url, newurl):
|
|
710
|
+
raise _UnsafeCDPRedirectError(
|
|
711
|
+
"Refusing CDP HTTP redirect with headers to a different host or port, "
|
|
712
|
+
"or an insecure endpoint"
|
|
713
|
+
)
|
|
714
|
+
return super().redirect_request(req, fp, code, msg, headers, newurl)
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
class _CDPWebSocketConnect(WebSocketConnect):
|
|
718
|
+
@override
|
|
719
|
+
def process_redirect(self, exc: Exception) -> Exception | str:
|
|
720
|
+
if (
|
|
721
|
+
self.additional_headers
|
|
722
|
+
and isinstance(exc, InvalidStatus)
|
|
723
|
+
and exc.response.status_code in (300, 301, 302, 303, 307, 308)
|
|
724
|
+
and "Location" in exc.response.headers
|
|
725
|
+
and not _can_forward_headers(
|
|
726
|
+
self.uri, urljoin(self.uri, exc.response.headers["Location"])
|
|
727
|
+
)
|
|
728
|
+
):
|
|
729
|
+
return _UnsafeCDPRedirectError(
|
|
730
|
+
"Refusing CDP WebSocket redirect with headers to a different host or port, "
|
|
731
|
+
"or an insecure endpoint"
|
|
732
|
+
)
|
|
733
|
+
return super().process_redirect(exc)
|
|
734
|
+
|
|
664
735
|
|
|
736
|
+
async def _connect_web_socket(url: str, *, headers: Mapping[str, str] | None = None) -> _WebSocket:
|
|
665
737
|
return cast(
|
|
666
738
|
_WebSocket,
|
|
667
|
-
await
|
|
739
|
+
await _CDPWebSocketConnect(
|
|
740
|
+
url, open_timeout=None, max_size=None, additional_headers=headers
|
|
741
|
+
),
|
|
668
742
|
)
|
|
669
743
|
|
|
670
744
|
|
|
671
|
-
async def _resolve_browser_web_socket_url(
|
|
745
|
+
async def _resolve_browser_web_socket_url(
|
|
746
|
+
cdp_url: str, *, headers: Mapping[str, str] | None = None
|
|
747
|
+
) -> str:
|
|
672
748
|
if cdp_url.startswith(("ws://", "wss://")):
|
|
673
749
|
return cdp_url
|
|
674
750
|
|
|
675
751
|
base_url = cdp_url.rstrip("/")
|
|
676
752
|
while True:
|
|
677
753
|
try:
|
|
678
|
-
version = await asyncio.to_thread(_read_json, f"{base_url}/json/version")
|
|
754
|
+
version = await asyncio.to_thread(_read_json, f"{base_url}/json/version", headers)
|
|
679
755
|
debugger_url = version.get("webSocketDebuggerUrl")
|
|
680
756
|
if isinstance(debugger_url, str) and debugger_url:
|
|
681
757
|
return debugger_url
|
|
758
|
+
except _UnsafeCDPRedirectError:
|
|
759
|
+
raise
|
|
760
|
+
except HTTPError as error:
|
|
761
|
+
error.close()
|
|
762
|
+
if error.code in (401, 403):
|
|
763
|
+
raise RuntimeError(
|
|
764
|
+
f"CDP discovery was rejected with HTTP {error.code}. "
|
|
765
|
+
"Check the gateway credentials and access permissions."
|
|
766
|
+
) from None
|
|
682
767
|
except Exception:
|
|
683
768
|
pass
|
|
684
769
|
await asyncio.sleep(0.25)
|
|
685
770
|
|
|
686
771
|
|
|
687
|
-
def _read_json(url: str) -> dict[str, object]:
|
|
688
|
-
|
|
772
|
+
def _read_json(url: str, headers: Mapping[str, str] | None = None) -> dict[str, object]:
|
|
773
|
+
request = Request(url, headers=dict(headers or {}))
|
|
774
|
+
# Keep the existing redirect behavior for connections without caller headers.
|
|
775
|
+
open_url = build_opener(_CDPRedirectHandler()).open if headers else urlopen
|
|
776
|
+
with open_url(request, timeout=2) as response:
|
|
689
777
|
value: Any = json.load(response)
|
|
690
778
|
if not isinstance(value, dict):
|
|
691
779
|
raise RuntimeError("CDP version endpoint returned invalid JSON")
|
|
@@ -18,7 +18,7 @@ from ._generated.models import (
|
|
|
18
18
|
StagehandResultMetadata,
|
|
19
19
|
TelemetryConfig,
|
|
20
20
|
)
|
|
21
|
-
from ._validation import WireModel, WireUrl, WireWebSocketUrl
|
|
21
|
+
from ._validation import WireHeaders, WireModel, WireUrl, WireWebSocketUrl
|
|
22
22
|
from .browserbase_session import DEFAULT_BROWSERBASE_URL
|
|
23
23
|
from .client_types import Cache as CacheInput
|
|
24
24
|
|
|
@@ -103,13 +103,16 @@ class LocalBrowserLaunchOptions(WireModel):
|
|
|
103
103
|
|
|
104
104
|
|
|
105
105
|
class LocalBrowserConnectOptions(WireModel):
|
|
106
|
-
|
|
106
|
+
# Headers may carry credentials, so validation errors never echo the input.
|
|
107
|
+
model_config = ConfigDict(extra="forbid", strict=True, hide_input_in_errors=True)
|
|
107
108
|
|
|
108
109
|
cdp_url: Annotated[str, Field(min_length=1)]
|
|
109
110
|
extension_id: str | None = None
|
|
110
111
|
"""Deprecated and ignored. Omit this field; Stagehand discovers the extension automatically."""
|
|
111
112
|
extension_cdp_url: WireWebSocketUrl | None = None
|
|
112
113
|
"""Browser-level CDP WebSocket the extension dials, when it differs from `cdp_url`."""
|
|
114
|
+
headers: WireHeaders | None = None
|
|
115
|
+
"""HTTP headers sent with the CDP connection, e.g. a gateway's credentials."""
|
|
113
116
|
|
|
114
117
|
|
|
115
118
|
class BrowserbaseClientOptions(WireModel):
|
|
@@ -69,6 +69,8 @@ class LocalBrowserConnectOptions(TypedDict):
|
|
|
69
69
|
"""Deprecated and ignored. Omit this field; Stagehand discovers the extension automatically."""
|
|
70
70
|
extension_cdp_url: NotRequired[str]
|
|
71
71
|
"""Browser-level CDP WebSocket the extension dials, when it differs from `cdp_url`."""
|
|
72
|
+
headers: NotRequired[dict[str, str]]
|
|
73
|
+
"""HTTP headers sent with the CDP connection, e.g. a gateway's credentials."""
|
|
72
74
|
|
|
73
75
|
|
|
74
76
|
class BrowserbaseClientOptions(TypedDict, total=False):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/_extension/content-script.js
RENAMED
|
File without changes
|
{stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/_extension/manifest.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/_generated/__init__.py
RENAMED
|
File without changes
|
{stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/_generated/input_types.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/browserbase_connection.py
RENAMED
|
File without changes
|
|
File without changes
|
{stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/browserbase_services.py
RENAMED
|
File without changes
|
{stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/browserbase_session.py
RENAMED
|
File without changes
|
{stagehand-4.3.0a0.dev1620 → stagehand-4.3.0a0.dev1624}/src/stagehand/browserbase_transport.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|