pi-playwright-cli 1.0.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 c-99-e
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # pi-playwright-cli
2
+
3
+ Browser automation skill for the [pi](https://shittycodingagent.ai) coding agent, powered by [`@playwright/cli`](https://www.npmjs.com/package/@playwright/cli).
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pi install git:github.com/c-99-e/pi-playwright-cli
9
+ ```
10
+
11
+ Pi will install `@playwright/cli` automatically and load the `playwright-cli` skill on startup.
12
+
13
+ ## Update
14
+
15
+ ```bash
16
+ pi update
17
+ ```
18
+
19
+ ## What the skill covers
20
+
21
+ - Navigate, click, type, fill, drag, hover, select
22
+ - Screenshots, PDFs, accessibility snapshots
23
+ - Multi-tab workflows
24
+ - Cookies, localStorage, sessionStorage
25
+ - Network route mocking
26
+ - Named browser sessions
27
+ - DevTools (console, network, tracing, video recording)
28
+ - Test generation
29
+
30
+ ## Usage
31
+
32
+ Once installed, just ask pi naturally:
33
+
34
+ ```
35
+ open playwright.dev and take a screenshot
36
+ fill out the login form at example.com
37
+ extract all product prices from this page
38
+ ```
39
+
40
+ Or load the skill explicitly:
41
+
42
+ ```
43
+ /skill:playwright-cli
44
+ ```
45
+
46
+ ## License
47
+
48
+ MIT
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "pi-playwright-cli",
3
+ "version": "1.0.0",
4
+ "description": "Browser automation skill for the pi coding agent, powered by @playwright/cli.",
5
+ "keywords": [
6
+ "pi-package",
7
+ "playwright",
8
+ "browser-automation",
9
+ "agent-skill"
10
+ ],
11
+ "homepage": "https://github.com/c-99-e/pi-playwright-cli",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/c-99-e/pi-playwright-cli.git"
15
+ },
16
+ "license": "MIT",
17
+ "files": [
18
+ "skills/",
19
+ "README.md",
20
+ "LICENSE"
21
+ ],
22
+ "dependencies": {
23
+ "@playwright/cli": "*"
24
+ },
25
+ "pi": {
26
+ "skills": ["./skills/"]
27
+ }
28
+ }
@@ -0,0 +1,278 @@
1
+ ---
2
+ name: playwright-cli
3
+ description: Automates browser interactions for web testing, form filling, screenshots, and data extraction. Use when the user needs to navigate websites, interact with web pages, fill forms, take screenshots, test web applications, or extract information from web pages.
4
+ allowed-tools: Bash(playwright-cli:*)
5
+ ---
6
+
7
+ # Browser Automation with playwright-cli
8
+
9
+ ## Quick start
10
+
11
+ ```bash
12
+ # open new browser
13
+ playwright-cli open
14
+ # navigate to a page
15
+ playwright-cli goto https://playwright.dev
16
+ # interact with the page using refs from the snapshot
17
+ playwright-cli click e15
18
+ playwright-cli type "page.click"
19
+ playwright-cli press Enter
20
+ # take a screenshot (rarely used, as snapshot is more common)
21
+ playwright-cli screenshot
22
+ # close the browser
23
+ playwright-cli close
24
+ ```
25
+
26
+ ## Commands
27
+
28
+ ### Core
29
+
30
+ ```bash
31
+ playwright-cli open
32
+ # open and navigate right away
33
+ playwright-cli open https://example.com/
34
+ playwright-cli goto https://playwright.dev
35
+ playwright-cli type "search query"
36
+ playwright-cli click e3
37
+ playwright-cli dblclick e7
38
+ playwright-cli fill e5 "user@example.com"
39
+ playwright-cli drag e2 e8
40
+ playwright-cli hover e4
41
+ playwright-cli select e9 "option-value"
42
+ playwright-cli upload ./document.pdf
43
+ playwright-cli check e12
44
+ playwright-cli uncheck e12
45
+ playwright-cli snapshot
46
+ playwright-cli snapshot --filename=after-click.yaml
47
+ playwright-cli eval "document.title"
48
+ playwright-cli eval "el => el.textContent" e5
49
+ playwright-cli dialog-accept
50
+ playwright-cli dialog-accept "confirmation text"
51
+ playwright-cli dialog-dismiss
52
+ playwright-cli resize 1920 1080
53
+ playwright-cli close
54
+ ```
55
+
56
+ ### Navigation
57
+
58
+ ```bash
59
+ playwright-cli go-back
60
+ playwright-cli go-forward
61
+ playwright-cli reload
62
+ ```
63
+
64
+ ### Keyboard
65
+
66
+ ```bash
67
+ playwright-cli press Enter
68
+ playwright-cli press ArrowDown
69
+ playwright-cli keydown Shift
70
+ playwright-cli keyup Shift
71
+ ```
72
+
73
+ ### Mouse
74
+
75
+ ```bash
76
+ playwright-cli mousemove 150 300
77
+ playwright-cli mousedown
78
+ playwright-cli mousedown right
79
+ playwright-cli mouseup
80
+ playwright-cli mouseup right
81
+ playwright-cli mousewheel 0 100
82
+ ```
83
+
84
+ ### Save as
85
+
86
+ ```bash
87
+ playwright-cli screenshot
88
+ playwright-cli screenshot e5
89
+ playwright-cli screenshot --filename=page.png
90
+ playwright-cli pdf --filename=page.pdf
91
+ ```
92
+
93
+ ### Tabs
94
+
95
+ ```bash
96
+ playwright-cli tab-list
97
+ playwright-cli tab-new
98
+ playwright-cli tab-new https://example.com/page
99
+ playwright-cli tab-close
100
+ playwright-cli tab-close 2
101
+ playwright-cli tab-select 0
102
+ ```
103
+
104
+ ### Storage
105
+
106
+ ```bash
107
+ playwright-cli state-save
108
+ playwright-cli state-save auth.json
109
+ playwright-cli state-load auth.json
110
+
111
+ # Cookies
112
+ playwright-cli cookie-list
113
+ playwright-cli cookie-list --domain=example.com
114
+ playwright-cli cookie-get session_id
115
+ playwright-cli cookie-set session_id abc123
116
+ playwright-cli cookie-set session_id abc123 --domain=example.com --httpOnly --secure
117
+ playwright-cli cookie-delete session_id
118
+ playwright-cli cookie-clear
119
+
120
+ # LocalStorage
121
+ playwright-cli localstorage-list
122
+ playwright-cli localstorage-get theme
123
+ playwright-cli localstorage-set theme dark
124
+ playwright-cli localstorage-delete theme
125
+ playwright-cli localstorage-clear
126
+
127
+ # SessionStorage
128
+ playwright-cli sessionstorage-list
129
+ playwright-cli sessionstorage-get step
130
+ playwright-cli sessionstorage-set step 3
131
+ playwright-cli sessionstorage-delete step
132
+ playwright-cli sessionstorage-clear
133
+ ```
134
+
135
+ ### Network
136
+
137
+ ```bash
138
+ playwright-cli route "**/*.jpg" --status=404
139
+ playwright-cli route "https://api.example.com/**" --body='{"mock": true}'
140
+ playwright-cli route-list
141
+ playwright-cli unroute "**/*.jpg"
142
+ playwright-cli unroute
143
+ ```
144
+
145
+ ### DevTools
146
+
147
+ ```bash
148
+ playwright-cli console
149
+ playwright-cli console warning
150
+ playwright-cli network
151
+ playwright-cli run-code "async page => await page.context().grantPermissions(['geolocation'])"
152
+ playwright-cli tracing-start
153
+ playwright-cli tracing-stop
154
+ playwright-cli video-start
155
+ playwright-cli video-stop video.webm
156
+ ```
157
+
158
+ ## Open parameters
159
+ ```bash
160
+ # Use specific browser when creating session
161
+ playwright-cli open --browser=chrome
162
+ playwright-cli open --browser=firefox
163
+ playwright-cli open --browser=webkit
164
+ playwright-cli open --browser=msedge
165
+ # Connect to browser via extension
166
+ playwright-cli open --extension
167
+
168
+ # Use persistent profile (by default profile is in-memory)
169
+ playwright-cli open --persistent
170
+ # Use persistent profile with custom directory
171
+ playwright-cli open --profile=/path/to/profile
172
+
173
+ # Start with config file
174
+ playwright-cli open --config=my-config.json
175
+
176
+ # Close the browser
177
+ playwright-cli close
178
+ # Delete user data for the default session
179
+ playwright-cli delete-data
180
+ ```
181
+
182
+ ## Snapshots
183
+
184
+ After each command, playwright-cli provides a snapshot of the current browser state.
185
+
186
+ ```bash
187
+ > playwright-cli goto https://example.com
188
+ ### Page
189
+ - Page URL: https://example.com/
190
+ - Page Title: Example Domain
191
+ ### Snapshot
192
+ [Snapshot](.playwright-cli/page-2026-02-14T19-22-42-679Z.yml)
193
+ ```
194
+
195
+ You can also take a snapshot on demand using `playwright-cli snapshot` command.
196
+
197
+ If `--filename` is not provided, a new snapshot file is created with a timestamp. Default to automatic file naming, use `--filename=` when artifact is a part of the workflow result.
198
+
199
+ ## Browser Sessions
200
+
201
+ ```bash
202
+ # create new browser session named "mysession" with persistent profile
203
+ playwright-cli -s=mysession open example.com --persistent
204
+ # same with manually specified profile directory (use when requested explicitly)
205
+ playwright-cli -s=mysession open example.com --profile=/path/to/profile
206
+ playwright-cli -s=mysession click e6
207
+ playwright-cli -s=mysession close # stop a named browser
208
+ playwright-cli -s=mysession delete-data # delete user data for persistent session
209
+
210
+ playwright-cli list
211
+ # Close all browsers
212
+ playwright-cli close-all
213
+ # Forcefully kill all browser processes
214
+ playwright-cli kill-all
215
+ ```
216
+
217
+ ## Local installation
218
+
219
+ In some cases user might want to install playwright-cli locally. If running globally available `playwright-cli` binary fails, use `npx playwright-cli` to run the commands. For example:
220
+
221
+ ```bash
222
+ npx playwright-cli open https://example.com
223
+ npx playwright-cli click e1
224
+ ```
225
+
226
+ ## Example: Form submission
227
+
228
+ ```bash
229
+ playwright-cli open https://example.com/form
230
+ playwright-cli snapshot
231
+
232
+ playwright-cli fill e1 "user@example.com"
233
+ playwright-cli fill e2 "password123"
234
+ playwright-cli click e3
235
+ playwright-cli snapshot
236
+ playwright-cli close
237
+ ```
238
+
239
+ ## Example: Multi-tab workflow
240
+
241
+ ```bash
242
+ playwright-cli open https://example.com
243
+ playwright-cli tab-new https://example.com/other
244
+ playwright-cli tab-list
245
+ playwright-cli tab-select 0
246
+ playwright-cli snapshot
247
+ playwright-cli close
248
+ ```
249
+
250
+ ## Example: Debugging with DevTools
251
+
252
+ ```bash
253
+ playwright-cli open https://example.com
254
+ playwright-cli click e4
255
+ playwright-cli fill e7 "test"
256
+ playwright-cli console
257
+ playwright-cli network
258
+ playwright-cli close
259
+ ```
260
+
261
+ ```bash
262
+ playwright-cli open https://example.com
263
+ playwright-cli tracing-start
264
+ playwright-cli click e4
265
+ playwright-cli fill e7 "test"
266
+ playwright-cli tracing-stop
267
+ playwright-cli close
268
+ ```
269
+
270
+ ## Specific tasks
271
+
272
+ * **Request mocking** [references/request-mocking.md](references/request-mocking.md)
273
+ * **Running Playwright code** [references/running-code.md](references/running-code.md)
274
+ * **Browser session management** [references/session-management.md](references/session-management.md)
275
+ * **Storage state (cookies, localStorage)** [references/storage-state.md](references/storage-state.md)
276
+ * **Test generation** [references/test-generation.md](references/test-generation.md)
277
+ * **Tracing** [references/tracing.md](references/tracing.md)
278
+ * **Video recording** [references/video-recording.md](references/video-recording.md)
@@ -0,0 +1,87 @@
1
+ # Request Mocking
2
+
3
+ Intercept, mock, modify, and block network requests.
4
+
5
+ ## CLI Route Commands
6
+
7
+ ```bash
8
+ # Mock with custom status
9
+ playwright-cli route "**/*.jpg" --status=404
10
+
11
+ # Mock with JSON body
12
+ playwright-cli route "**/api/users" --body='[{"id":1,"name":"Alice"}]' --content-type=application/json
13
+
14
+ # Mock with custom headers
15
+ playwright-cli route "**/api/data" --body='{"ok":true}' --header="X-Custom: value"
16
+
17
+ # Remove headers from requests
18
+ playwright-cli route "**/*" --remove-header=cookie,authorization
19
+
20
+ # List active routes
21
+ playwright-cli route-list
22
+
23
+ # Remove a route or all routes
24
+ playwright-cli unroute "**/*.jpg"
25
+ playwright-cli unroute
26
+ ```
27
+
28
+ ## URL Patterns
29
+
30
+ ```
31
+ **/api/users - Exact path match
32
+ **/api/*/details - Wildcard in path
33
+ **/*.{png,jpg,jpeg} - Match file extensions
34
+ **/search?q=* - Match query parameters
35
+ ```
36
+
37
+ ## Advanced Mocking with run-code
38
+
39
+ For conditional responses, request body inspection, response modification, or delays:
40
+
41
+ ### Conditional Response Based on Request
42
+
43
+ ```bash
44
+ playwright-cli run-code "async page => {
45
+ await page.route('**/api/login', route => {
46
+ const body = route.request().postDataJSON();
47
+ if (body.username === 'admin') {
48
+ route.fulfill({ body: JSON.stringify({ token: 'mock-token' }) });
49
+ } else {
50
+ route.fulfill({ status: 401, body: JSON.stringify({ error: 'Invalid' }) });
51
+ }
52
+ });
53
+ }"
54
+ ```
55
+
56
+ ### Modify Real Response
57
+
58
+ ```bash
59
+ playwright-cli run-code "async page => {
60
+ await page.route('**/api/user', async route => {
61
+ const response = await route.fetch();
62
+ const json = await response.json();
63
+ json.isPremium = true;
64
+ await route.fulfill({ response, json });
65
+ });
66
+ }"
67
+ ```
68
+
69
+ ### Simulate Network Failures
70
+
71
+ ```bash
72
+ playwright-cli run-code "async page => {
73
+ await page.route('**/api/offline', route => route.abort('internetdisconnected'));
74
+ }"
75
+ # Options: connectionrefused, timedout, connectionreset, internetdisconnected
76
+ ```
77
+
78
+ ### Delayed Response
79
+
80
+ ```bash
81
+ playwright-cli run-code "async page => {
82
+ await page.route('**/api/slow', async route => {
83
+ await new Promise(r => setTimeout(r, 3000));
84
+ route.fulfill({ body: JSON.stringify({ data: 'loaded' }) });
85
+ });
86
+ }"
87
+ ```
@@ -0,0 +1,232 @@
1
+ # Running Custom Playwright Code
2
+
3
+ Use `run-code` to execute arbitrary Playwright code for advanced scenarios not covered by CLI commands.
4
+
5
+ ## Syntax
6
+
7
+ ```bash
8
+ playwright-cli run-code "async page => {
9
+ // Your Playwright code here
10
+ // Access page.context() for browser context operations
11
+ }"
12
+ ```
13
+
14
+ ## Geolocation
15
+
16
+ ```bash
17
+ # Grant geolocation permission and set location
18
+ playwright-cli run-code "async page => {
19
+ await page.context().grantPermissions(['geolocation']);
20
+ await page.context().setGeolocation({ latitude: 37.7749, longitude: -122.4194 });
21
+ }"
22
+
23
+ # Set location to London
24
+ playwright-cli run-code "async page => {
25
+ await page.context().grantPermissions(['geolocation']);
26
+ await page.context().setGeolocation({ latitude: 51.5074, longitude: -0.1278 });
27
+ }"
28
+
29
+ # Clear geolocation override
30
+ playwright-cli run-code "async page => {
31
+ await page.context().clearPermissions();
32
+ }"
33
+ ```
34
+
35
+ ## Permissions
36
+
37
+ ```bash
38
+ # Grant multiple permissions
39
+ playwright-cli run-code "async page => {
40
+ await page.context().grantPermissions([
41
+ 'geolocation',
42
+ 'notifications',
43
+ 'camera',
44
+ 'microphone'
45
+ ]);
46
+ }"
47
+
48
+ # Grant permissions for specific origin
49
+ playwright-cli run-code "async page => {
50
+ await page.context().grantPermissions(['clipboard-read'], {
51
+ origin: 'https://example.com'
52
+ });
53
+ }"
54
+ ```
55
+
56
+ ## Media Emulation
57
+
58
+ ```bash
59
+ # Emulate dark color scheme
60
+ playwright-cli run-code "async page => {
61
+ await page.emulateMedia({ colorScheme: 'dark' });
62
+ }"
63
+
64
+ # Emulate light color scheme
65
+ playwright-cli run-code "async page => {
66
+ await page.emulateMedia({ colorScheme: 'light' });
67
+ }"
68
+
69
+ # Emulate reduced motion
70
+ playwright-cli run-code "async page => {
71
+ await page.emulateMedia({ reducedMotion: 'reduce' });
72
+ }"
73
+
74
+ # Emulate print media
75
+ playwright-cli run-code "async page => {
76
+ await page.emulateMedia({ media: 'print' });
77
+ }"
78
+ ```
79
+
80
+ ## Wait Strategies
81
+
82
+ ```bash
83
+ # Wait for network idle
84
+ playwright-cli run-code "async page => {
85
+ await page.waitForLoadState('networkidle');
86
+ }"
87
+
88
+ # Wait for specific element
89
+ playwright-cli run-code "async page => {
90
+ await page.waitForSelector('.loading', { state: 'hidden' });
91
+ }"
92
+
93
+ # Wait for function to return true
94
+ playwright-cli run-code "async page => {
95
+ await page.waitForFunction(() => window.appReady === true);
96
+ }"
97
+
98
+ # Wait with timeout
99
+ playwright-cli run-code "async page => {
100
+ await page.waitForSelector('.result', { timeout: 10000 });
101
+ }"
102
+ ```
103
+
104
+ ## Frames and Iframes
105
+
106
+ ```bash
107
+ # Work with iframe
108
+ playwright-cli run-code "async page => {
109
+ const frame = page.locator('iframe#my-iframe').contentFrame();
110
+ await frame.locator('button').click();
111
+ }"
112
+
113
+ # Get all frames
114
+ playwright-cli run-code "async page => {
115
+ const frames = page.frames();
116
+ return frames.map(f => f.url());
117
+ }"
118
+ ```
119
+
120
+ ## File Downloads
121
+
122
+ ```bash
123
+ # Handle file download
124
+ playwright-cli run-code "async page => {
125
+ const [download] = await Promise.all([
126
+ page.waitForEvent('download'),
127
+ page.click('a.download-link')
128
+ ]);
129
+ await download.saveAs('./downloaded-file.pdf');
130
+ return download.suggestedFilename();
131
+ }"
132
+ ```
133
+
134
+ ## Clipboard
135
+
136
+ ```bash
137
+ # Read clipboard (requires permission)
138
+ playwright-cli run-code "async page => {
139
+ await page.context().grantPermissions(['clipboard-read']);
140
+ return await page.evaluate(() => navigator.clipboard.readText());
141
+ }"
142
+
143
+ # Write to clipboard
144
+ playwright-cli run-code "async page => {
145
+ await page.evaluate(text => navigator.clipboard.writeText(text), 'Hello clipboard!');
146
+ }"
147
+ ```
148
+
149
+ ## Page Information
150
+
151
+ ```bash
152
+ # Get page title
153
+ playwright-cli run-code "async page => {
154
+ return await page.title();
155
+ }"
156
+
157
+ # Get current URL
158
+ playwright-cli run-code "async page => {
159
+ return page.url();
160
+ }"
161
+
162
+ # Get page content
163
+ playwright-cli run-code "async page => {
164
+ return await page.content();
165
+ }"
166
+
167
+ # Get viewport size
168
+ playwright-cli run-code "async page => {
169
+ return page.viewportSize();
170
+ }"
171
+ ```
172
+
173
+ ## JavaScript Execution
174
+
175
+ ```bash
176
+ # Execute JavaScript and return result
177
+ playwright-cli run-code "async page => {
178
+ return await page.evaluate(() => {
179
+ return {
180
+ userAgent: navigator.userAgent,
181
+ language: navigator.language,
182
+ cookiesEnabled: navigator.cookieEnabled
183
+ };
184
+ });
185
+ }"
186
+
187
+ # Pass arguments to evaluate
188
+ playwright-cli run-code "async page => {
189
+ const multiplier = 5;
190
+ return await page.evaluate(m => document.querySelectorAll('li').length * m, multiplier);
191
+ }"
192
+ ```
193
+
194
+ ## Error Handling
195
+
196
+ ```bash
197
+ # Try-catch in run-code
198
+ playwright-cli run-code "async page => {
199
+ try {
200
+ await page.click('.maybe-missing', { timeout: 1000 });
201
+ return 'clicked';
202
+ } catch (e) {
203
+ return 'element not found';
204
+ }
205
+ }"
206
+ ```
207
+
208
+ ## Complex Workflows
209
+
210
+ ```bash
211
+ # Login and save state
212
+ playwright-cli run-code "async page => {
213
+ await page.goto('https://example.com/login');
214
+ await page.fill('input[name=email]', 'user@example.com');
215
+ await page.fill('input[name=password]', 'secret');
216
+ await page.click('button[type=submit]');
217
+ await page.waitForURL('**/dashboard');
218
+ await page.context().storageState({ path: 'auth.json' });
219
+ return 'Login successful';
220
+ }"
221
+
222
+ # Scrape data from multiple pages
223
+ playwright-cli run-code "async page => {
224
+ const results = [];
225
+ for (let i = 1; i <= 3; i++) {
226
+ await page.goto(\`https://example.com/page/\${i}\`);
227
+ const items = await page.locator('.item').allTextContents();
228
+ results.push(...items);
229
+ }
230
+ return results;
231
+ }"
232
+ ```
@@ -0,0 +1,169 @@
1
+ # Browser Session Management
2
+
3
+ Run multiple isolated browser sessions concurrently with state persistence.
4
+
5
+ ## Named Browser Sessions
6
+
7
+ Use `-s` flag to isolate browser contexts:
8
+
9
+ ```bash
10
+ # Browser 1: Authentication flow
11
+ playwright-cli -s=auth open https://app.example.com/login
12
+
13
+ # Browser 2: Public browsing (separate cookies, storage)
14
+ playwright-cli -s=public open https://example.com
15
+
16
+ # Commands are isolated by browser session
17
+ playwright-cli -s=auth fill e1 "user@example.com"
18
+ playwright-cli -s=public snapshot
19
+ ```
20
+
21
+ ## Browser Session Isolation Properties
22
+
23
+ Each browser session has independent:
24
+ - Cookies
25
+ - LocalStorage / SessionStorage
26
+ - IndexedDB
27
+ - Cache
28
+ - Browsing history
29
+ - Open tabs
30
+
31
+ ## Browser Session Commands
32
+
33
+ ```bash
34
+ # List all browser sessions
35
+ playwright-cli list
36
+
37
+ # Stop a browser session (close the browser)
38
+ playwright-cli close # stop the default browser
39
+ playwright-cli -s=mysession close # stop a named browser
40
+
41
+ # Stop all browser sessions
42
+ playwright-cli close-all
43
+
44
+ # Forcefully kill all daemon processes (for stale/zombie processes)
45
+ playwright-cli kill-all
46
+
47
+ # Delete browser session user data (profile directory)
48
+ playwright-cli delete-data # delete default browser data
49
+ playwright-cli -s=mysession delete-data # delete named browser data
50
+ ```
51
+
52
+ ## Environment Variable
53
+
54
+ Set a default browser session name via environment variable:
55
+
56
+ ```bash
57
+ export PLAYWRIGHT_CLI_SESSION="mysession"
58
+ playwright-cli open example.com # Uses "mysession" automatically
59
+ ```
60
+
61
+ ## Common Patterns
62
+
63
+ ### Concurrent Scraping
64
+
65
+ ```bash
66
+ #!/bin/bash
67
+ # Scrape multiple sites concurrently
68
+
69
+ # Start all browsers
70
+ playwright-cli -s=site1 open https://site1.com &
71
+ playwright-cli -s=site2 open https://site2.com &
72
+ playwright-cli -s=site3 open https://site3.com &
73
+ wait
74
+
75
+ # Take snapshots from each
76
+ playwright-cli -s=site1 snapshot
77
+ playwright-cli -s=site2 snapshot
78
+ playwright-cli -s=site3 snapshot
79
+
80
+ # Cleanup
81
+ playwright-cli close-all
82
+ ```
83
+
84
+ ### A/B Testing Sessions
85
+
86
+ ```bash
87
+ # Test different user experiences
88
+ playwright-cli -s=variant-a open "https://app.com?variant=a"
89
+ playwright-cli -s=variant-b open "https://app.com?variant=b"
90
+
91
+ # Compare
92
+ playwright-cli -s=variant-a screenshot
93
+ playwright-cli -s=variant-b screenshot
94
+ ```
95
+
96
+ ### Persistent Profile
97
+
98
+ By default, browser profile is kept in memory only. Use `--persistent` flag on `open` to persist the browser profile to disk:
99
+
100
+ ```bash
101
+ # Use persistent profile (auto-generated location)
102
+ playwright-cli open https://example.com --persistent
103
+
104
+ # Use persistent profile with custom directory
105
+ playwright-cli open https://example.com --profile=/path/to/profile
106
+ ```
107
+
108
+ ## Default Browser Session
109
+
110
+ When `-s` is omitted, commands use the default browser session:
111
+
112
+ ```bash
113
+ # These use the same default browser session
114
+ playwright-cli open https://example.com
115
+ playwright-cli snapshot
116
+ playwright-cli close # Stops default browser
117
+ ```
118
+
119
+ ## Browser Session Configuration
120
+
121
+ Configure a browser session with specific settings when opening:
122
+
123
+ ```bash
124
+ # Open with config file
125
+ playwright-cli open https://example.com --config=.playwright/my-cli.json
126
+
127
+ # Open with specific browser
128
+ playwright-cli open https://example.com --browser=firefox
129
+
130
+ # Open in headed mode
131
+ playwright-cli open https://example.com --headed
132
+
133
+ # Open with persistent profile
134
+ playwright-cli open https://example.com --persistent
135
+ ```
136
+
137
+ ## Best Practices
138
+
139
+ ### 1. Name Browser Sessions Semantically
140
+
141
+ ```bash
142
+ # GOOD: Clear purpose
143
+ playwright-cli -s=github-auth open https://github.com
144
+ playwright-cli -s=docs-scrape open https://docs.example.com
145
+
146
+ # AVOID: Generic names
147
+ playwright-cli -s=s1 open https://github.com
148
+ ```
149
+
150
+ ### 2. Always Clean Up
151
+
152
+ ```bash
153
+ # Stop browsers when done
154
+ playwright-cli -s=auth close
155
+ playwright-cli -s=scrape close
156
+
157
+ # Or stop all at once
158
+ playwright-cli close-all
159
+
160
+ # If browsers become unresponsive or zombie processes remain
161
+ playwright-cli kill-all
162
+ ```
163
+
164
+ ### 3. Delete Stale Browser Data
165
+
166
+ ```bash
167
+ # Remove old browser data to free disk space
168
+ playwright-cli -s=oldsession delete-data
169
+ ```
@@ -0,0 +1,275 @@
1
+ # Storage Management
2
+
3
+ Manage cookies, localStorage, sessionStorage, and browser storage state.
4
+
5
+ ## Storage State
6
+
7
+ Save and restore complete browser state including cookies and storage.
8
+
9
+ ### Save Storage State
10
+
11
+ ```bash
12
+ # Save to auto-generated filename (storage-state-{timestamp}.json)
13
+ playwright-cli state-save
14
+
15
+ # Save to specific filename
16
+ playwright-cli state-save my-auth-state.json
17
+ ```
18
+
19
+ ### Restore Storage State
20
+
21
+ ```bash
22
+ # Load storage state from file
23
+ playwright-cli state-load my-auth-state.json
24
+
25
+ # Reload page to apply cookies
26
+ playwright-cli open https://example.com
27
+ ```
28
+
29
+ ### Storage State File Format
30
+
31
+ The saved file contains:
32
+
33
+ ```json
34
+ {
35
+ "cookies": [
36
+ {
37
+ "name": "session_id",
38
+ "value": "abc123",
39
+ "domain": "example.com",
40
+ "path": "/",
41
+ "expires": 1735689600,
42
+ "httpOnly": true,
43
+ "secure": true,
44
+ "sameSite": "Lax"
45
+ }
46
+ ],
47
+ "origins": [
48
+ {
49
+ "origin": "https://example.com",
50
+ "localStorage": [
51
+ { "name": "theme", "value": "dark" },
52
+ { "name": "user_id", "value": "12345" }
53
+ ]
54
+ }
55
+ ]
56
+ }
57
+ ```
58
+
59
+ ## Cookies
60
+
61
+ ### List All Cookies
62
+
63
+ ```bash
64
+ playwright-cli cookie-list
65
+ ```
66
+
67
+ ### Filter Cookies by Domain
68
+
69
+ ```bash
70
+ playwright-cli cookie-list --domain=example.com
71
+ ```
72
+
73
+ ### Filter Cookies by Path
74
+
75
+ ```bash
76
+ playwright-cli cookie-list --path=/api
77
+ ```
78
+
79
+ ### Get Specific Cookie
80
+
81
+ ```bash
82
+ playwright-cli cookie-get session_id
83
+ ```
84
+
85
+ ### Set a Cookie
86
+
87
+ ```bash
88
+ # Basic cookie
89
+ playwright-cli cookie-set session abc123
90
+
91
+ # Cookie with options
92
+ playwright-cli cookie-set session abc123 --domain=example.com --path=/ --httpOnly --secure --sameSite=Lax
93
+
94
+ # Cookie with expiration (Unix timestamp)
95
+ playwright-cli cookie-set remember_me token123 --expires=1735689600
96
+ ```
97
+
98
+ ### Delete a Cookie
99
+
100
+ ```bash
101
+ playwright-cli cookie-delete session_id
102
+ ```
103
+
104
+ ### Clear All Cookies
105
+
106
+ ```bash
107
+ playwright-cli cookie-clear
108
+ ```
109
+
110
+ ### Advanced: Multiple Cookies or Custom Options
111
+
112
+ For complex scenarios like adding multiple cookies at once, use `run-code`:
113
+
114
+ ```bash
115
+ playwright-cli run-code "async page => {
116
+ await page.context().addCookies([
117
+ { name: 'session_id', value: 'sess_abc123', domain: 'example.com', path: '/', httpOnly: true },
118
+ { name: 'preferences', value: JSON.stringify({ theme: 'dark' }), domain: 'example.com', path: '/' }
119
+ ]);
120
+ }"
121
+ ```
122
+
123
+ ## Local Storage
124
+
125
+ ### List All localStorage Items
126
+
127
+ ```bash
128
+ playwright-cli localstorage-list
129
+ ```
130
+
131
+ ### Get Single Value
132
+
133
+ ```bash
134
+ playwright-cli localstorage-get token
135
+ ```
136
+
137
+ ### Set Value
138
+
139
+ ```bash
140
+ playwright-cli localstorage-set theme dark
141
+ ```
142
+
143
+ ### Set JSON Value
144
+
145
+ ```bash
146
+ playwright-cli localstorage-set user_settings '{"theme":"dark","language":"en"}'
147
+ ```
148
+
149
+ ### Delete Single Item
150
+
151
+ ```bash
152
+ playwright-cli localstorage-delete token
153
+ ```
154
+
155
+ ### Clear All localStorage
156
+
157
+ ```bash
158
+ playwright-cli localstorage-clear
159
+ ```
160
+
161
+ ### Advanced: Multiple Operations
162
+
163
+ For complex scenarios like setting multiple values at once, use `run-code`:
164
+
165
+ ```bash
166
+ playwright-cli run-code "async page => {
167
+ await page.evaluate(() => {
168
+ localStorage.setItem('token', 'jwt_abc123');
169
+ localStorage.setItem('user_id', '12345');
170
+ localStorage.setItem('expires_at', Date.now() + 3600000);
171
+ });
172
+ }"
173
+ ```
174
+
175
+ ## Session Storage
176
+
177
+ ### List All sessionStorage Items
178
+
179
+ ```bash
180
+ playwright-cli sessionstorage-list
181
+ ```
182
+
183
+ ### Get Single Value
184
+
185
+ ```bash
186
+ playwright-cli sessionstorage-get form_data
187
+ ```
188
+
189
+ ### Set Value
190
+
191
+ ```bash
192
+ playwright-cli sessionstorage-set step 3
193
+ ```
194
+
195
+ ### Delete Single Item
196
+
197
+ ```bash
198
+ playwright-cli sessionstorage-delete step
199
+ ```
200
+
201
+ ### Clear sessionStorage
202
+
203
+ ```bash
204
+ playwright-cli sessionstorage-clear
205
+ ```
206
+
207
+ ## IndexedDB
208
+
209
+ ### List Databases
210
+
211
+ ```bash
212
+ playwright-cli run-code "async page => {
213
+ return await page.evaluate(async () => {
214
+ const databases = await indexedDB.databases();
215
+ return databases;
216
+ });
217
+ }"
218
+ ```
219
+
220
+ ### Delete Database
221
+
222
+ ```bash
223
+ playwright-cli run-code "async page => {
224
+ await page.evaluate(() => {
225
+ indexedDB.deleteDatabase('myDatabase');
226
+ });
227
+ }"
228
+ ```
229
+
230
+ ## Common Patterns
231
+
232
+ ### Authentication State Reuse
233
+
234
+ ```bash
235
+ # Step 1: Login and save state
236
+ playwright-cli open https://app.example.com/login
237
+ playwright-cli snapshot
238
+ playwright-cli fill e1 "user@example.com"
239
+ playwright-cli fill e2 "password123"
240
+ playwright-cli click e3
241
+
242
+ # Save the authenticated state
243
+ playwright-cli state-save auth.json
244
+
245
+ # Step 2: Later, restore state and skip login
246
+ playwright-cli state-load auth.json
247
+ playwright-cli open https://app.example.com/dashboard
248
+ # Already logged in!
249
+ ```
250
+
251
+ ### Save and Restore Roundtrip
252
+
253
+ ```bash
254
+ # Set up authentication state
255
+ playwright-cli open https://example.com
256
+ playwright-cli eval "() => { document.cookie = 'session=abc123'; localStorage.setItem('user', 'john'); }"
257
+
258
+ # Save state to file
259
+ playwright-cli state-save my-session.json
260
+
261
+ # ... later, in a new session ...
262
+
263
+ # Restore state
264
+ playwright-cli state-load my-session.json
265
+ playwright-cli open https://example.com
266
+ # Cookies and localStorage are restored!
267
+ ```
268
+
269
+ ## Security Notes
270
+
271
+ - Never commit storage state files containing auth tokens
272
+ - Add `*.auth-state.json` to `.gitignore`
273
+ - Delete state files after automation completes
274
+ - Use environment variables for sensitive data
275
+ - By default, sessions run in-memory mode which is safer for sensitive operations
@@ -0,0 +1,88 @@
1
+ # Test Generation
2
+
3
+ Generate Playwright test code automatically as you interact with the browser.
4
+
5
+ ## How It Works
6
+
7
+ Every action you perform with `playwright-cli` generates corresponding Playwright TypeScript code.
8
+ This code appears in the output and can be copied directly into your test files.
9
+
10
+ ## Example Workflow
11
+
12
+ ```bash
13
+ # Start a session
14
+ playwright-cli open https://example.com/login
15
+
16
+ # Take a snapshot to see elements
17
+ playwright-cli snapshot
18
+ # Output shows: e1 [textbox "Email"], e2 [textbox "Password"], e3 [button "Sign In"]
19
+
20
+ # Fill form fields - generates code automatically
21
+ playwright-cli fill e1 "user@example.com"
22
+ # Ran Playwright code:
23
+ # await page.getByRole('textbox', { name: 'Email' }).fill('user@example.com');
24
+
25
+ playwright-cli fill e2 "password123"
26
+ # Ran Playwright code:
27
+ # await page.getByRole('textbox', { name: 'Password' }).fill('password123');
28
+
29
+ playwright-cli click e3
30
+ # Ran Playwright code:
31
+ # await page.getByRole('button', { name: 'Sign In' }).click();
32
+ ```
33
+
34
+ ## Building a Test File
35
+
36
+ Collect the generated code into a Playwright test:
37
+
38
+ ```typescript
39
+ import { test, expect } from '@playwright/test';
40
+
41
+ test('login flow', async ({ page }) => {
42
+ // Generated code from playwright-cli session:
43
+ await page.goto('https://example.com/login');
44
+ await page.getByRole('textbox', { name: 'Email' }).fill('user@example.com');
45
+ await page.getByRole('textbox', { name: 'Password' }).fill('password123');
46
+ await page.getByRole('button', { name: 'Sign In' }).click();
47
+
48
+ // Add assertions
49
+ await expect(page).toHaveURL(/.*dashboard/);
50
+ });
51
+ ```
52
+
53
+ ## Best Practices
54
+
55
+ ### 1. Use Semantic Locators
56
+
57
+ The generated code uses role-based locators when possible, which are more resilient:
58
+
59
+ ```typescript
60
+ // Generated (good - semantic)
61
+ await page.getByRole('button', { name: 'Submit' }).click();
62
+
63
+ // Avoid (fragile - CSS selectors)
64
+ await page.locator('#submit-btn').click();
65
+ ```
66
+
67
+ ### 2. Explore Before Recording
68
+
69
+ Take snapshots to understand the page structure before recording actions:
70
+
71
+ ```bash
72
+ playwright-cli open https://example.com
73
+ playwright-cli snapshot
74
+ # Review the element structure
75
+ playwright-cli click e5
76
+ ```
77
+
78
+ ### 3. Add Assertions Manually
79
+
80
+ Generated code captures actions but not assertions. Add expectations in your test:
81
+
82
+ ```typescript
83
+ // Generated action
84
+ await page.getByRole('button', { name: 'Submit' }).click();
85
+
86
+ // Manual assertion
87
+ await expect(page.getByText('Success')).toBeVisible();
88
+ ```
@@ -0,0 +1,139 @@
1
+ # Tracing
2
+
3
+ Capture detailed execution traces for debugging and analysis. Traces include DOM snapshots, screenshots, network activity, and console logs.
4
+
5
+ ## Basic Usage
6
+
7
+ ```bash
8
+ # Start trace recording
9
+ playwright-cli tracing-start
10
+
11
+ # Perform actions
12
+ playwright-cli open https://example.com
13
+ playwright-cli click e1
14
+ playwright-cli fill e2 "test"
15
+
16
+ # Stop trace recording
17
+ playwright-cli tracing-stop
18
+ ```
19
+
20
+ ## Trace Output Files
21
+
22
+ When you start tracing, Playwright creates a `traces/` directory with several files:
23
+
24
+ ### `trace-{timestamp}.trace`
25
+
26
+ **Action log** - The main trace file containing:
27
+ - Every action performed (clicks, fills, navigations)
28
+ - DOM snapshots before and after each action
29
+ - Screenshots at each step
30
+ - Timing information
31
+ - Console messages
32
+ - Source locations
33
+
34
+ ### `trace-{timestamp}.network`
35
+
36
+ **Network log** - Complete network activity:
37
+ - All HTTP requests and responses
38
+ - Request headers and bodies
39
+ - Response headers and bodies
40
+ - Timing (DNS, connect, TLS, TTFB, download)
41
+ - Resource sizes
42
+ - Failed requests and errors
43
+
44
+ ### `resources/`
45
+
46
+ **Resources directory** - Cached resources:
47
+ - Images, fonts, stylesheets, scripts
48
+ - Response bodies for replay
49
+ - Assets needed to reconstruct page state
50
+
51
+ ## What Traces Capture
52
+
53
+ | Category | Details |
54
+ |----------|---------|
55
+ | **Actions** | Clicks, fills, hovers, keyboard input, navigations |
56
+ | **DOM** | Full DOM snapshot before/after each action |
57
+ | **Screenshots** | Visual state at each step |
58
+ | **Network** | All requests, responses, headers, bodies, timing |
59
+ | **Console** | All console.log, warn, error messages |
60
+ | **Timing** | Precise timing for each operation |
61
+
62
+ ## Use Cases
63
+
64
+ ### Debugging Failed Actions
65
+
66
+ ```bash
67
+ playwright-cli tracing-start
68
+ playwright-cli open https://app.example.com
69
+
70
+ # This click fails - why?
71
+ playwright-cli click e5
72
+
73
+ playwright-cli tracing-stop
74
+ # Open trace to see DOM state when click was attempted
75
+ ```
76
+
77
+ ### Analyzing Performance
78
+
79
+ ```bash
80
+ playwright-cli tracing-start
81
+ playwright-cli open https://slow-site.com
82
+ playwright-cli tracing-stop
83
+
84
+ # View network waterfall to identify slow resources
85
+ ```
86
+
87
+ ### Capturing Evidence
88
+
89
+ ```bash
90
+ # Record a complete user flow for documentation
91
+ playwright-cli tracing-start
92
+
93
+ playwright-cli open https://app.example.com/checkout
94
+ playwright-cli fill e1 "4111111111111111"
95
+ playwright-cli fill e2 "12/25"
96
+ playwright-cli fill e3 "123"
97
+ playwright-cli click e4
98
+
99
+ playwright-cli tracing-stop
100
+ # Trace shows exact sequence of events
101
+ ```
102
+
103
+ ## Trace vs Video vs Screenshot
104
+
105
+ | Feature | Trace | Video | Screenshot |
106
+ |---------|-------|-------|------------|
107
+ | **Format** | .trace file | .webm video | .png/.jpeg image |
108
+ | **DOM inspection** | Yes | No | No |
109
+ | **Network details** | Yes | No | No |
110
+ | **Step-by-step replay** | Yes | Continuous | Single frame |
111
+ | **File size** | Medium | Large | Small |
112
+ | **Best for** | Debugging | Demos | Quick capture |
113
+
114
+ ## Best Practices
115
+
116
+ ### 1. Start Tracing Before the Problem
117
+
118
+ ```bash
119
+ # Trace the entire flow, not just the failing step
120
+ playwright-cli tracing-start
121
+ playwright-cli open https://example.com
122
+ # ... all steps leading to the issue ...
123
+ playwright-cli tracing-stop
124
+ ```
125
+
126
+ ### 2. Clean Up Old Traces
127
+
128
+ Traces can consume significant disk space:
129
+
130
+ ```bash
131
+ # Remove traces older than 7 days
132
+ find .playwright-cli/traces -mtime +7 -delete
133
+ ```
134
+
135
+ ## Limitations
136
+
137
+ - Traces add overhead to automation
138
+ - Large traces can consume significant disk space
139
+ - Some dynamic content may not replay perfectly
@@ -0,0 +1,43 @@
1
+ # Video Recording
2
+
3
+ Capture browser automation sessions as video for debugging, documentation, or verification. Produces WebM (VP8/VP9 codec).
4
+
5
+ ## Basic Recording
6
+
7
+ ```bash
8
+ # Start recording
9
+ playwright-cli video-start
10
+
11
+ # Perform actions
12
+ playwright-cli open https://example.com
13
+ playwright-cli snapshot
14
+ playwright-cli click e1
15
+ playwright-cli fill e2 "test input"
16
+
17
+ # Stop and save
18
+ playwright-cli video-stop demo.webm
19
+ ```
20
+
21
+ ## Best Practices
22
+
23
+ ### 1. Use Descriptive Filenames
24
+
25
+ ```bash
26
+ # Include context in filename
27
+ playwright-cli video-stop recordings/login-flow-2024-01-15.webm
28
+ playwright-cli video-stop recordings/checkout-test-run-42.webm
29
+ ```
30
+
31
+ ## Tracing vs Video
32
+
33
+ | Feature | Video | Tracing |
34
+ |---------|-------|---------|
35
+ | Output | WebM file | Trace file (viewable in Trace Viewer) |
36
+ | Shows | Visual recording | DOM snapshots, network, console, actions |
37
+ | Use case | Demos, documentation | Debugging, analysis |
38
+ | Size | Larger | Smaller |
39
+
40
+ ## Limitations
41
+
42
+ - Recording adds slight overhead to automation
43
+ - Large recordings can consume significant disk space