Skip to content

Commit ca5d188

Browse files
committed
docs: flesh out browser-scoped example
Turn the browser-scoped Python example into a runnable demonstration of both process execution and /curl/raw-backed request and stream usage. Made-with: Cursor
1 parent a80716b commit ca5d188

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

examples/browser_scoped.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,22 @@
22

33
from kernel import Kernel
44

5-
# After creating or loading a browser session (with base_url + cdp_ws_url from the API):
6-
# browser = client.browsers.create(...)
7-
# scoped = client.for_browser(browser)
8-
# scoped.process.exec(command="uname", args=["-a"])
9-
# r = scoped.request("GET", "https://example.com")
10-
# with scoped.stream("GET", "https://example.com") as resp:
11-
# print(resp.read())
12-
135

146
def main() -> None:
15-
_ = Kernel
7+
with Kernel() as client:
8+
browser = client.browsers.create(headless=True)
9+
try:
10+
scoped = client.for_browser(browser)
11+
12+
scoped.process.exec(command="uname", args=["-a"])
13+
14+
response = scoped.request("GET", "https://example.com")
15+
print("status", response.status_code)
16+
17+
with scoped.stream("GET", "https://example.com") as streamed:
18+
print("streamed-bytes", len(streamed.read()))
19+
finally:
20+
client.browsers.delete_by_id(browser.session_id)
1621

1722

1823
if __name__ == "__main__":

0 commit comments

Comments
 (0)