@nickduy/agent-studio 0.1.4 → 0.1.6

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.
@@ -1,247 +1,247 @@
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
- You can also load the function from a file:
15
-
16
- ```bash
17
- playwright-cli run-code --filename=./my-script.js
18
- ```
19
-
20
-
21
- The code must be a single function expression, it is wrapped in `(...)` and evaluated.
22
- import/export/require syntax is not supported.
23
-
24
- The code runs in an isolated context, not in a full Node.js environment. `require`, `process` and Node modules are not
25
- available. Timers (`setTimeout`, `setInterval`), `fetch`, `URL`, `Buffer`, `crypto`, `AbortController`, `TextEncoder`
26
- and `TextDecoder` are available.
27
-
28
- ## Geolocation
29
-
30
- ```bash
31
- # Grant geolocation permission and set location
32
- playwright-cli run-code "async page => {
33
- await page.context().grantPermissions(['geolocation']);
34
- await page.context().setGeolocation({ latitude: 37.7749, longitude: -122.4194 });
35
- }"
36
-
37
- # Set location to London
38
- playwright-cli run-code "async page => {
39
- await page.context().grantPermissions(['geolocation']);
40
- await page.context().setGeolocation({ latitude: 51.5074, longitude: -0.1278 });
41
- }"
42
-
43
- # Clear geolocation override
44
- playwright-cli run-code "async page => {
45
- await page.context().clearPermissions();
46
- }"
47
- ```
48
-
49
- ## Permissions
50
-
51
- ```bash
52
- # Grant multiple permissions
53
- playwright-cli run-code "async page => {
54
- await page.context().grantPermissions([
55
- 'geolocation',
56
- 'notifications',
57
- 'camera',
58
- 'microphone'
59
- ]);
60
- }"
61
-
62
- # Grant permissions for specific origin
63
- playwright-cli run-code "async page => {
64
- await page.context().grantPermissions(['clipboard-read'], {
65
- origin: 'https://example.com'
66
- });
67
- }"
68
- ```
69
-
70
- ## Media Emulation
71
-
72
- ```bash
73
- # Emulate dark color scheme
74
- playwright-cli run-code "async page => {
75
- await page.emulateMedia({ colorScheme: 'dark' });
76
- }"
77
-
78
- # Emulate light color scheme
79
- playwright-cli run-code "async page => {
80
- await page.emulateMedia({ colorScheme: 'light' });
81
- }"
82
-
83
- # Emulate reduced motion
84
- playwright-cli run-code "async page => {
85
- await page.emulateMedia({ reducedMotion: 'reduce' });
86
- }"
87
-
88
- # Emulate print media
89
- playwright-cli run-code "async page => {
90
- await page.emulateMedia({ media: 'print' });
91
- }"
92
- ```
93
-
94
- ## Wait Strategies
95
-
96
- ```bash
97
- # Wait for network idle
98
- playwright-cli run-code "async page => {
99
- await page.waitForLoadState('networkidle');
100
- }"
101
-
102
- # Wait for specific element
103
- playwright-cli run-code "async page => {
104
- await page.locator('.loading').waitFor({ state: 'hidden' });
105
- }"
106
-
107
- # Wait for function to return true
108
- playwright-cli run-code "async page => {
109
- await page.waitForFunction(() => window.appReady === true);
110
- }"
111
-
112
- # Wait with timeout
113
- playwright-cli run-code "async page => {
114
- await page.locator('.result').waitFor({ timeout: 10000 });
115
- }"
116
- ```
117
-
118
- ## Frames and Iframes
119
-
120
- ```bash
121
- # Work with iframe
122
- playwright-cli run-code "async page => {
123
- const frame = page.locator('iframe#my-iframe').contentFrame();
124
- await frame.locator('button').click();
125
- }"
126
-
127
- # Get all frames
128
- playwright-cli run-code "async page => {
129
- const frames = page.frames();
130
- return frames.map(f => f.url());
131
- }"
132
- ```
133
-
134
- ## File Downloads
135
-
136
- ```bash
137
- # Handle file download
138
- playwright-cli run-code "async page => {
139
- const downloadPromise = page.waitForEvent('download');
140
- await page.getByRole('link', { name: 'Download' }).click();
141
- const download = await downloadPromise;
142
- await download.saveAs('./downloaded-file.pdf');
143
- return download.suggestedFilename();
144
- }"
145
- ```
146
-
147
- ## Clipboard
148
-
149
- ```bash
150
- # Read clipboard (requires permission)
151
- playwright-cli run-code "async page => {
152
- await page.context().grantPermissions(['clipboard-read']);
153
- return await page.evaluate(() => navigator.clipboard.readText());
154
- }"
155
-
156
- # Write to clipboard
157
- playwright-cli run-code "async page => {
158
- await page.evaluate(text => navigator.clipboard.writeText(text), 'Hello clipboard!');
159
- }"
160
- ```
161
-
162
- ## Page Information
163
-
164
- ```bash
165
- # Get page title
166
- playwright-cli run-code "async page => {
167
- return await page.title();
168
- }"
169
-
170
- # Get current URL
171
- playwright-cli run-code "async page => {
172
- return page.url();
173
- }"
174
-
175
- # Get page content
176
- playwright-cli run-code "async page => {
177
- return await page.content();
178
- }"
179
-
180
- # Get viewport size
181
- playwright-cli run-code "async page => {
182
- return page.viewportSize();
183
- }"
184
- ```
185
-
186
- ## JavaScript Execution
187
-
188
- ```bash
189
- # Execute JavaScript and return result
190
- playwright-cli run-code "async page => {
191
- return await page.evaluate(() => {
192
- return {
193
- userAgent: navigator.userAgent,
194
- language: navigator.language,
195
- cookiesEnabled: navigator.cookieEnabled
196
- };
197
- });
198
- }"
199
-
200
- # Pass arguments to evaluate
201
- playwright-cli run-code "async page => {
202
- const multiplier = 5;
203
- return await page.evaluate(m => document.querySelectorAll('li').length * m, multiplier);
204
- }"
205
- ```
206
-
207
- ## Error Handling
208
-
209
- ```bash
210
- # Try-catch in run-code
211
- playwright-cli run-code "async page => {
212
- try {
213
- await page.getByRole('button', { name: 'Submit' }).click({ timeout: 1000 });
214
- return 'clicked';
215
- } catch (e) {
216
- return 'element not found';
217
- }
218
- }"
219
- ```
220
-
221
- Event listener errors are reported as console errors.
222
-
223
- ## Complex Workflows
224
-
225
- ```bash
226
- # Login and save state
227
- playwright-cli run-code "async page => {
228
- await page.goto('https://example.com/login');
229
- await page.getByRole('textbox', { name: 'Email' }).fill('user@example.com');
230
- await page.getByRole('textbox', { name: 'Password' }).fill('secret');
231
- await page.getByRole('button', { name: 'Sign in' }).click();
232
- await page.waitForURL('**/dashboard');
233
- await page.context().storageState({ path: 'auth.json' });
234
- return 'Login successful';
235
- }"
236
-
237
- # Scrape data from multiple pages
238
- playwright-cli run-code "async page => {
239
- const results = [];
240
- for (let i = 1; i <= 3; i++) {
241
- await page.goto(\`https://example.com/page/\${i}\`);
242
- const items = await page.locator('.item').allTextContents();
243
- results.push(...items);
244
- }
245
- return results;
246
- }"
247
- ```
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
+ You can also load the function from a file:
15
+
16
+ ```bash
17
+ playwright-cli run-code --filename=./my-script.js
18
+ ```
19
+
20
+
21
+ The code must be a single function expression, it is wrapped in `(...)` and evaluated.
22
+ import/export/require syntax is not supported.
23
+
24
+ The code runs in an isolated context, not in a full Node.js environment. `require`, `process` and Node modules are not
25
+ available. Timers (`setTimeout`, `setInterval`), `fetch`, `URL`, `Buffer`, `crypto`, `AbortController`, `TextEncoder`
26
+ and `TextDecoder` are available.
27
+
28
+ ## Geolocation
29
+
30
+ ```bash
31
+ # Grant geolocation permission and set location
32
+ playwright-cli run-code "async page => {
33
+ await page.context().grantPermissions(['geolocation']);
34
+ await page.context().setGeolocation({ latitude: 37.7749, longitude: -122.4194 });
35
+ }"
36
+
37
+ # Set location to London
38
+ playwright-cli run-code "async page => {
39
+ await page.context().grantPermissions(['geolocation']);
40
+ await page.context().setGeolocation({ latitude: 51.5074, longitude: -0.1278 });
41
+ }"
42
+
43
+ # Clear geolocation override
44
+ playwright-cli run-code "async page => {
45
+ await page.context().clearPermissions();
46
+ }"
47
+ ```
48
+
49
+ ## Permissions
50
+
51
+ ```bash
52
+ # Grant multiple permissions
53
+ playwright-cli run-code "async page => {
54
+ await page.context().grantPermissions([
55
+ 'geolocation',
56
+ 'notifications',
57
+ 'camera',
58
+ 'microphone'
59
+ ]);
60
+ }"
61
+
62
+ # Grant permissions for specific origin
63
+ playwright-cli run-code "async page => {
64
+ await page.context().grantPermissions(['clipboard-read'], {
65
+ origin: 'https://example.com'
66
+ });
67
+ }"
68
+ ```
69
+
70
+ ## Media Emulation
71
+
72
+ ```bash
73
+ # Emulate dark color scheme
74
+ playwright-cli run-code "async page => {
75
+ await page.emulateMedia({ colorScheme: 'dark' });
76
+ }"
77
+
78
+ # Emulate light color scheme
79
+ playwright-cli run-code "async page => {
80
+ await page.emulateMedia({ colorScheme: 'light' });
81
+ }"
82
+
83
+ # Emulate reduced motion
84
+ playwright-cli run-code "async page => {
85
+ await page.emulateMedia({ reducedMotion: 'reduce' });
86
+ }"
87
+
88
+ # Emulate print media
89
+ playwright-cli run-code "async page => {
90
+ await page.emulateMedia({ media: 'print' });
91
+ }"
92
+ ```
93
+
94
+ ## Wait Strategies
95
+
96
+ ```bash
97
+ # Wait for network idle
98
+ playwright-cli run-code "async page => {
99
+ await page.waitForLoadState('networkidle');
100
+ }"
101
+
102
+ # Wait for specific element
103
+ playwright-cli run-code "async page => {
104
+ await page.locator('.loading').waitFor({ state: 'hidden' });
105
+ }"
106
+
107
+ # Wait for function to return true
108
+ playwright-cli run-code "async page => {
109
+ await page.waitForFunction(() => window.appReady === true);
110
+ }"
111
+
112
+ # Wait with timeout
113
+ playwright-cli run-code "async page => {
114
+ await page.locator('.result').waitFor({ timeout: 10000 });
115
+ }"
116
+ ```
117
+
118
+ ## Frames and Iframes
119
+
120
+ ```bash
121
+ # Work with iframe
122
+ playwright-cli run-code "async page => {
123
+ const frame = page.locator('iframe#my-iframe').contentFrame();
124
+ await frame.locator('button').click();
125
+ }"
126
+
127
+ # Get all frames
128
+ playwright-cli run-code "async page => {
129
+ const frames = page.frames();
130
+ return frames.map(f => f.url());
131
+ }"
132
+ ```
133
+
134
+ ## File Downloads
135
+
136
+ ```bash
137
+ # Handle file download
138
+ playwright-cli run-code "async page => {
139
+ const downloadPromise = page.waitForEvent('download');
140
+ await page.getByRole('link', { name: 'Download' }).click();
141
+ const download = await downloadPromise;
142
+ await download.saveAs('./downloaded-file.pdf');
143
+ return download.suggestedFilename();
144
+ }"
145
+ ```
146
+
147
+ ## Clipboard
148
+
149
+ ```bash
150
+ # Read clipboard (requires permission)
151
+ playwright-cli run-code "async page => {
152
+ await page.context().grantPermissions(['clipboard-read']);
153
+ return await page.evaluate(() => navigator.clipboard.readText());
154
+ }"
155
+
156
+ # Write to clipboard
157
+ playwright-cli run-code "async page => {
158
+ await page.evaluate(text => navigator.clipboard.writeText(text), 'Hello clipboard!');
159
+ }"
160
+ ```
161
+
162
+ ## Page Information
163
+
164
+ ```bash
165
+ # Get page title
166
+ playwright-cli run-code "async page => {
167
+ return await page.title();
168
+ }"
169
+
170
+ # Get current URL
171
+ playwright-cli run-code "async page => {
172
+ return page.url();
173
+ }"
174
+
175
+ # Get page content
176
+ playwright-cli run-code "async page => {
177
+ return await page.content();
178
+ }"
179
+
180
+ # Get viewport size
181
+ playwright-cli run-code "async page => {
182
+ return page.viewportSize();
183
+ }"
184
+ ```
185
+
186
+ ## JavaScript Execution
187
+
188
+ ```bash
189
+ # Execute JavaScript and return result
190
+ playwright-cli run-code "async page => {
191
+ return await page.evaluate(() => {
192
+ return {
193
+ userAgent: navigator.userAgent,
194
+ language: navigator.language,
195
+ cookiesEnabled: navigator.cookieEnabled
196
+ };
197
+ });
198
+ }"
199
+
200
+ # Pass arguments to evaluate
201
+ playwright-cli run-code "async page => {
202
+ const multiplier = 5;
203
+ return await page.evaluate(m => document.querySelectorAll('li').length * m, multiplier);
204
+ }"
205
+ ```
206
+
207
+ ## Error Handling
208
+
209
+ ```bash
210
+ # Try-catch in run-code
211
+ playwright-cli run-code "async page => {
212
+ try {
213
+ await page.getByRole('button', { name: 'Submit' }).click({ timeout: 1000 });
214
+ return 'clicked';
215
+ } catch (e) {
216
+ return 'element not found';
217
+ }
218
+ }"
219
+ ```
220
+
221
+ Event listener errors are reported as console errors.
222
+
223
+ ## Complex Workflows
224
+
225
+ ```bash
226
+ # Login and save state
227
+ playwright-cli run-code "async page => {
228
+ await page.goto('https://example.com/login');
229
+ await page.getByRole('textbox', { name: 'Email' }).fill('user@example.com');
230
+ await page.getByRole('textbox', { name: 'Password' }).fill('secret');
231
+ await page.getByRole('button', { name: 'Sign in' }).click();
232
+ await page.waitForURL('**/dashboard');
233
+ await page.context().storageState({ path: 'auth.json' });
234
+ return 'Login successful';
235
+ }"
236
+
237
+ # Scrape data from multiple pages
238
+ playwright-cli run-code "async page => {
239
+ const results = [];
240
+ for (let i = 1; i <= 3; i++) {
241
+ await page.goto(\`https://example.com/page/\${i}\`);
242
+ const items = await page.locator('.item').allTextContents();
243
+ results.push(...items);
244
+ }
245
+ return results;
246
+ }"
247
+ ```