form-tester 0.2.3
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/.claude/skills/playwright-cli/SKILL.md +278 -0
- package/.claude/skills/playwright-cli/references/request-mocking.md +87 -0
- package/.claude/skills/playwright-cli/references/running-code.md +232 -0
- package/.claude/skills/playwright-cli/references/session-management.md +169 -0
- package/.claude/skills/playwright-cli/references/storage-state.md +275 -0
- package/.claude/skills/playwright-cli/references/test-generation.md +88 -0
- package/.claude/skills/playwright-cli/references/tracing.md +139 -0
- package/.claude/skills/playwright-cli/references/video-recording.md +43 -0
- package/README.md +75 -0
- package/form-tester.config.example.json +3 -0
- package/form-tester.js +984 -0
- package/package.json +26 -0
- package/tests/form-tester.test.js +120 -0
|
@@ -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
|
+
```
|