shalpha 4.0.0rc54__py3-none-any.whl
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.
- shalpha-4.0.0rc54.dist-info/METADATA +141 -0
- shalpha-4.0.0rc54.dist-info/RECORD +7 -0
- shalpha-4.0.0rc54.dist-info/WHEEL +4 -0
- stagehand/__init__.py +4 -0
- stagehand/client.py +27513 -0
- stagehand/runtime.py +1609 -0
- stagehand/stagehand-extension-4.0.0-rc.54.zip +0 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: shalpha
|
|
3
|
+
Version: 4.0.0rc54
|
|
4
|
+
Summary: Python SDK for Stagehand
|
|
5
|
+
Project-URL: Repository, https://github.com/browserbase/stagehand-v4
|
|
6
|
+
Requires-Python: >=3.11
|
|
7
|
+
Requires-Dist: abxbus==2.5.18
|
|
8
|
+
Requires-Dist: browserbase>=1.8.0
|
|
9
|
+
Requires-Dist: pydantic>=2.0
|
|
10
|
+
Requires-Dist: rich-click>=1.8
|
|
11
|
+
Requires-Dist: rich>=13.9
|
|
12
|
+
Requires-Dist: websocket-client>=1.8.0
|
|
13
|
+
Requires-Dist: websockets>=14.0
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# Stagehand SDK Client (Python)
|
|
17
|
+
|
|
18
|
+
Python SDK for controlling the Stagehand extension through ModCDP.
|
|
19
|
+
|
|
20
|
+
## Run
|
|
21
|
+
|
|
22
|
+
From the repository root:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pnpm run build:artifacts
|
|
26
|
+
pnpm --filter @browserbasehq/stagehand-docs test:examples:python
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
For the CI smoke flow that exercises raw CDP, ModCDP, and GitHub summary output:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
uv run python tests/integration/test_basic.py
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
import asyncio
|
|
39
|
+
import os
|
|
40
|
+
|
|
41
|
+
from stagehand import StagehandClient
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
async def main() -> None:
|
|
45
|
+
client = StagehandClient(
|
|
46
|
+
# Pass at most one launch source:
|
|
47
|
+
# cdp_url="http://127.0.0.1:9222",
|
|
48
|
+
# cdp_url="ws://127.0.0.1:9222/devtools/browser/<id>",
|
|
49
|
+
# local_browser_launch_options={
|
|
50
|
+
# "executable_path": "/Applications/Chromium.app/Contents/MacOS/Chromium",
|
|
51
|
+
# },
|
|
52
|
+
# browserbase_session_create_params={
|
|
53
|
+
# "browserbase_api_key": os.environ["BROWSERBASE_API_KEY"],
|
|
54
|
+
# },
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
await client.connect()
|
|
58
|
+
|
|
59
|
+
client.on("Target.targetInfoChanged", print)
|
|
60
|
+
|
|
61
|
+
print(await client.Browser.getVersion())
|
|
62
|
+
print(await client.Target.getTargets())
|
|
63
|
+
print(await client.Mod.evaluate(expression="chrome.runtime.id"))
|
|
64
|
+
|
|
65
|
+
browser = client.browser
|
|
66
|
+
page = await browser.new_page(url="https://example.com")
|
|
67
|
+
page2 = await page.goto(url="https://browserbase.com")
|
|
68
|
+
print(page2.url)
|
|
69
|
+
print(await browser.pages(url=page2.url))
|
|
70
|
+
|
|
71
|
+
body = await page.locate(css="body")
|
|
72
|
+
print(await body.info())
|
|
73
|
+
|
|
74
|
+
await client.close()
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
asyncio.run(main())
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`StagehandClient.connect()` and `StagehandClient.close()` are async. Stagehand browser/page/locator methods are async. The compact `client.*` CDP command surface is synchronous because the Python ModCDP client owns a background websocket reader thread.
|
|
81
|
+
|
|
82
|
+
## Launch Sources
|
|
83
|
+
|
|
84
|
+
`connect()` accepts exactly one effective launch source:
|
|
85
|
+
|
|
86
|
+
- `cdp_url`: an existing browser CDP endpoint. `http://...` URLs are resolved through `/json/version`; `ws://...` and `wss://...` URLs are used directly.
|
|
87
|
+
- `local_browser_launch_options`: launches local Chromium or Chrome Canary with CDP enabled. `CHROME_PATH` can provide the executable path. `STAGEHAND_SDK_CDP_PORT` fixes the debugging port for editor attach workflows.
|
|
88
|
+
- `browserbase_session_create_params["browserbase_api_key"]`: asks ModCDP to create a Browserbase session. The SDK uploads or reuses the packaged versioned extension artifact automatically; no extension ID configuration is required.
|
|
89
|
+
|
|
90
|
+
If no launch source is passed, `connect()` reads `os.environ`; it uses `BROWSERBASE_API_KEY` when present, otherwise it launches local Chromium/Canary.
|
|
91
|
+
|
|
92
|
+
## Extension Paths
|
|
93
|
+
|
|
94
|
+
The default unpacked extension directory is the WXT output:
|
|
95
|
+
|
|
96
|
+
```text
|
|
97
|
+
stagehand-extension/.output/chrome-mv3
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
The same directory contains the single reusable extension zip:
|
|
101
|
+
|
|
102
|
+
```text
|
|
103
|
+
stagehand-extension/.output/chrome-mv3/stagehand-extension.zip
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
The prepared extension manifest uses the canonical `stagehand-modcdp/background.js` service worker path. The client trusts and waits for that service worker with `globalThis.__stagehand_modcdp_ready === true`.
|
|
107
|
+
|
|
108
|
+
## Routing
|
|
109
|
+
|
|
110
|
+
Default client routes:
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
{
|
|
114
|
+
"Mod.*": "service_worker",
|
|
115
|
+
"Stagehand.*": "service_worker",
|
|
116
|
+
"*.*": "service_worker",
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Default extension service-worker routes:
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
{
|
|
124
|
+
"Mod.*": "service_worker",
|
|
125
|
+
"Stagehand.*": "service_worker",
|
|
126
|
+
"*.*": "loopback_cdp",
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Stagehand SDK routes are fixed: Stagehand and ModCDP commands go through the extension service worker, and native CDP commands go from the service worker to loopback CDP.
|
|
131
|
+
|
|
132
|
+
## Debugging
|
|
133
|
+
|
|
134
|
+
The checked-in VS Code tasks set:
|
|
135
|
+
|
|
136
|
+
```text
|
|
137
|
+
STAGEHAND_DEBUG_WAIT_FOR_ENTER=1
|
|
138
|
+
STAGEHAND_SDK_CDP_PORT=9231
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
The smoke test at `tests/integration/test_basic.py` prints `[debug] Browser ready. Press Enter to continue.` after the extension is connected, so DevTools can inspect `chrome-extension://*/stagehand-modcdp/background.js` before the flow continues.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
stagehand/__init__.py,sha256=pbWdf_OXV76abwO3YtbUQkm4xbGlaQlIpxtu2jIK1xg,114
|
|
2
|
+
stagehand/client.py,sha256=hUdlBNB6E_RJBg-w7FQSE9u0tTnpx3UxRq1zf5Qv-X0,1298871
|
|
3
|
+
stagehand/runtime.py,sha256=7FygucIu9sKMo5UroGjN53yilRcm_dKDmMeIHczxusg,61049
|
|
4
|
+
stagehand/stagehand-extension-4.0.0-rc.54.zip,sha256=ApYBoqK5mAZOLfoz9c4K1PYOVlg45FKanfqriDNkYD8,2753669
|
|
5
|
+
shalpha-4.0.0rc54.dist-info/METADATA,sha256=-Z4LHUu073AT8kWN1z7_f6BCCBZ4FDmcZjLjZG1GWas,4396
|
|
6
|
+
shalpha-4.0.0rc54.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
7
|
+
shalpha-4.0.0rc54.dist-info/RECORD,,
|
stagehand/__init__.py
ADDED