Skip to content

Commit 220956e

Browse files
docs: replace Python demo with CLI one-liner for smooth movement
Swap the Python smooth_demo.py script in the Tip with a pure bash snippet using the kernel CLI. Users can copy-paste and run immediately without creating any files. Made-with: Cursor
1 parent 6c94c1c commit 220956e

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

browsers/computer-controls.mdx

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,7 @@ title: "Computer Controls"
33
description: "Control the computer's mouse, keyboard, and screen"
44
---
55

6-
Use OS-level controls to move and click the mouse, type and press keys, scroll, drag, and capture screenshots from a running browser session.
7-
8-
<Tip>
9-
Smooth movement is enabled by default — every `moveMouse` and `dragMouse` call already uses [Bézier curves](https://en.wikipedia.org/wiki/B%C3%A9zier_curve). Run this script and open the [live view](/browsers/live-view) link to watch it in action:
10-
11-
```python smooth_demo.py
12-
from kernel import Kernel
13-
import time, urllib.request
14-
15-
k = Kernel()
16-
b = k.browsers.create()
17-
print(f"\n Watch live: {b.live_view_url}\n")
18-
19-
html = urllib.request.urlopen(
20-
"https://gist.githubusercontent.com/ulziibay-kernel/f6d8063ba223a81293cfe1fde06d8624/raw/cursor-trail-demo.html"
21-
).read().decode()
22-
k.browsers.playwright.execute(id=b.session_id, code="await page.setContent(" + repr(html) + ");")
23-
input("Press Enter when live view is open...")
24-
25-
for x, y in [(200, 200), (900, 150), (1700, 250), (1700, 700), (960, 800), (200, 750), (500, 480), (1400, 480)]:
26-
k.browsers.computer.move_mouse(id=b.session_id, x=x, y=y, duration_ms=1200)
27-
time.sleep(0.3)
28-
```
29-
</Tip>
6+
Use OS-level controls to move and click the mouse, type and press keys, scroll, drag, and capture screenshots from a running browser session. Both `moveMouse` and `dragMouse` use human-like [Bézier curves](https://en.wikipedia.org/wiki/B%C3%A9zier_curve) by default.
307

318
## Click the mouse
329

@@ -177,6 +154,28 @@ kernel browsers computer move-mouse <session id> --x 500 --y 300 --smooth=false
177154
<img src="/images/smooth-mouse-demo.gif" />
178155
</Frame>
179156

157+
Try it yourself — open [live view](/browsers/live-view) and paste this (requires CLI v0.15.4+ — run `kernel upgrade` to update):
158+
159+
```bash
160+
ID=$(kernel browsers create -o json | jq -r '.session_id')
161+
echo "Open live view: https://dashboard.onkernel.com/browsers/$ID"
162+
HTML=$(curl -sL "https://gist.githubusercontent.com/ulziibay-kernel/f6d8063ba223a81293cfe1fde06d8624/raw/cursor-trail-demo.html")
163+
kernel browsers playwright execute $ID "await page.setContent($(echo "$HTML" | jq -Rs .))"
164+
sleep 3
165+
166+
kernel browsers playwright execute $ID "await page.evaluate(() => document.dispatchEvent(new CustomEvent('kernel-mode', {detail:'smooth'})))"
167+
for coords in "200 200" "900 150" "1700 250" "1700 700" "960 800" "200 750"; do
168+
kernel browsers computer move-mouse $ID --x ${coords% *} --y ${coords#* } --duration-ms 1200
169+
sleep 0.3
170+
done
171+
172+
kernel browsers playwright execute $ID "await page.evaluate(() => document.dispatchEvent(new CustomEvent('kernel-mode', {detail:'instant'})))"
173+
for coords in "200 200" "900 150" "1700 250" "1700 700" "960 800" "200 750"; do
174+
kernel browsers computer move-mouse $ID --x ${coords% *} --y ${coords#* } --smooth=false
175+
sleep 0.5
176+
done
177+
```
178+
180179
## Take screenshots
181180

182181
Capture a full-screen PNG or a specific region.

0 commit comments

Comments
 (0)