e2e-pilot 0.0.69

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.
Files changed (152) hide show
  1. package/bin.js +3 -0
  2. package/dist/aria-snapshot.d.ts +95 -0
  3. package/dist/aria-snapshot.d.ts.map +1 -0
  4. package/dist/aria-snapshot.js +490 -0
  5. package/dist/aria-snapshot.js.map +1 -0
  6. package/dist/bippy.js +971 -0
  7. package/dist/cdp-relay.d.ts +16 -0
  8. package/dist/cdp-relay.d.ts.map +1 -0
  9. package/dist/cdp-relay.js +715 -0
  10. package/dist/cdp-relay.js.map +1 -0
  11. package/dist/cdp-session.d.ts +42 -0
  12. package/dist/cdp-session.d.ts.map +1 -0
  13. package/dist/cdp-session.js +154 -0
  14. package/dist/cdp-session.js.map +1 -0
  15. package/dist/cdp-types.d.ts +63 -0
  16. package/dist/cdp-types.d.ts.map +1 -0
  17. package/dist/cdp-types.js +91 -0
  18. package/dist/cdp-types.js.map +1 -0
  19. package/dist/cli.d.ts +3 -0
  20. package/dist/cli.d.ts.map +1 -0
  21. package/dist/cli.js +213 -0
  22. package/dist/cli.js.map +1 -0
  23. package/dist/create-logger.d.ts +9 -0
  24. package/dist/create-logger.d.ts.map +1 -0
  25. package/dist/create-logger.js +25 -0
  26. package/dist/create-logger.js.map +1 -0
  27. package/dist/debugger-api.md +458 -0
  28. package/dist/debugger-examples-types.d.ts +24 -0
  29. package/dist/debugger-examples-types.d.ts.map +1 -0
  30. package/dist/debugger-examples-types.js +2 -0
  31. package/dist/debugger-examples-types.js.map +1 -0
  32. package/dist/debugger-examples.d.ts +6 -0
  33. package/dist/debugger-examples.d.ts.map +1 -0
  34. package/dist/debugger-examples.js +53 -0
  35. package/dist/debugger-examples.js.map +1 -0
  36. package/dist/debugger.d.ts +381 -0
  37. package/dist/debugger.d.ts.map +1 -0
  38. package/dist/debugger.js +633 -0
  39. package/dist/debugger.js.map +1 -0
  40. package/dist/editor-api.md +364 -0
  41. package/dist/editor-examples.d.ts +11 -0
  42. package/dist/editor-examples.d.ts.map +1 -0
  43. package/dist/editor-examples.js +124 -0
  44. package/dist/editor-examples.js.map +1 -0
  45. package/dist/editor.d.ts +203 -0
  46. package/dist/editor.d.ts.map +1 -0
  47. package/dist/editor.js +336 -0
  48. package/dist/editor.js.map +1 -0
  49. package/dist/execute.d.ts +50 -0
  50. package/dist/execute.d.ts.map +1 -0
  51. package/dist/execute.js +576 -0
  52. package/dist/execute.js.map +1 -0
  53. package/dist/index.d.ts +11 -0
  54. package/dist/index.d.ts.map +1 -0
  55. package/dist/index.js +7 -0
  56. package/dist/index.js.map +1 -0
  57. package/dist/mcp-client.d.ts +20 -0
  58. package/dist/mcp-client.d.ts.map +1 -0
  59. package/dist/mcp-client.js +56 -0
  60. package/dist/mcp-client.js.map +1 -0
  61. package/dist/mcp.d.ts +5 -0
  62. package/dist/mcp.d.ts.map +1 -0
  63. package/dist/mcp.js +720 -0
  64. package/dist/mcp.js.map +1 -0
  65. package/dist/mcp.test.d.ts +10 -0
  66. package/dist/mcp.test.d.ts.map +1 -0
  67. package/dist/mcp.test.js +2999 -0
  68. package/dist/mcp.test.js.map +1 -0
  69. package/dist/network-capture.d.ts +23 -0
  70. package/dist/network-capture.d.ts.map +1 -0
  71. package/dist/network-capture.js +98 -0
  72. package/dist/network-capture.js.map +1 -0
  73. package/dist/protocol.d.ts +54 -0
  74. package/dist/protocol.d.ts.map +1 -0
  75. package/dist/protocol.js +2 -0
  76. package/dist/protocol.js.map +1 -0
  77. package/dist/react-source.d.ts +13 -0
  78. package/dist/react-source.d.ts.map +1 -0
  79. package/dist/react-source.js +68 -0
  80. package/dist/react-source.js.map +1 -0
  81. package/dist/scoped-fs.d.ts +94 -0
  82. package/dist/scoped-fs.d.ts.map +1 -0
  83. package/dist/scoped-fs.js +356 -0
  84. package/dist/scoped-fs.js.map +1 -0
  85. package/dist/selector-generator.js +8126 -0
  86. package/dist/start-relay-server.d.ts +6 -0
  87. package/dist/start-relay-server.d.ts.map +1 -0
  88. package/dist/start-relay-server.js +33 -0
  89. package/dist/start-relay-server.js.map +1 -0
  90. package/dist/styles-api.md +117 -0
  91. package/dist/styles-examples.d.ts +8 -0
  92. package/dist/styles-examples.d.ts.map +1 -0
  93. package/dist/styles-examples.js +64 -0
  94. package/dist/styles-examples.js.map +1 -0
  95. package/dist/styles.d.ts +27 -0
  96. package/dist/styles.d.ts.map +1 -0
  97. package/dist/styles.js +234 -0
  98. package/dist/styles.js.map +1 -0
  99. package/dist/trace-utils.d.ts +14 -0
  100. package/dist/trace-utils.d.ts.map +1 -0
  101. package/dist/trace-utils.js +21 -0
  102. package/dist/trace-utils.js.map +1 -0
  103. package/dist/utils.d.ts +20 -0
  104. package/dist/utils.d.ts.map +1 -0
  105. package/dist/utils.js +75 -0
  106. package/dist/utils.js.map +1 -0
  107. package/dist/wait-for-page-load.d.ts +16 -0
  108. package/dist/wait-for-page-load.d.ts.map +1 -0
  109. package/dist/wait-for-page-load.js +127 -0
  110. package/dist/wait-for-page-load.js.map +1 -0
  111. package/package.json +67 -0
  112. package/src/aria-snapshot.ts +610 -0
  113. package/src/assets/aria-labels-github-snapshot.txt +605 -0
  114. package/src/assets/aria-labels-github.png +0 -0
  115. package/src/assets/aria-labels-google-snapshot.txt +49 -0
  116. package/src/assets/aria-labels-google.png +0 -0
  117. package/src/assets/aria-labels-hacker-news-snapshot.txt +1023 -0
  118. package/src/assets/aria-labels-hacker-news.png +0 -0
  119. package/src/cdp-relay.ts +925 -0
  120. package/src/cdp-session.ts +203 -0
  121. package/src/cdp-timing.md +128 -0
  122. package/src/cdp-types.ts +155 -0
  123. package/src/cli.ts +250 -0
  124. package/src/create-logger.ts +36 -0
  125. package/src/debugger-examples-types.ts +13 -0
  126. package/src/debugger-examples.ts +66 -0
  127. package/src/debugger.md +453 -0
  128. package/src/debugger.ts +713 -0
  129. package/src/editor-examples.ts +148 -0
  130. package/src/editor.ts +390 -0
  131. package/src/execute.ts +763 -0
  132. package/src/index.ts +10 -0
  133. package/src/mcp-client.ts +78 -0
  134. package/src/mcp.test.ts +3596 -0
  135. package/src/mcp.ts +876 -0
  136. package/src/network-capture.ts +140 -0
  137. package/src/prompt.bak.md +323 -0
  138. package/src/prompt.md +7 -0
  139. package/src/protocol.ts +63 -0
  140. package/src/react-source.ts +94 -0
  141. package/src/resource.md +436 -0
  142. package/src/scoped-fs.ts +411 -0
  143. package/src/snapshots/hacker-news-focused-accessibility.md +202 -0
  144. package/src/snapshots/hacker-news-initial-accessibility.md +11 -0
  145. package/src/snapshots/hacker-news-tabbed-accessibility.md +202 -0
  146. package/src/snapshots/shadcn-ui-accessibility.md +11 -0
  147. package/src/start-relay-server.ts +43 -0
  148. package/src/styles-examples.ts +77 -0
  149. package/src/styles.ts +345 -0
  150. package/src/trace-utils.ts +43 -0
  151. package/src/utils.ts +91 -0
  152. package/src/wait-for-page-load.ts +174 -0
@@ -0,0 +1,364 @@
1
+ # Editor API Reference
2
+
3
+ The Editor class provides a Claude Code-like interface for viewing and editing web page scripts at runtime.
4
+
5
+ ## Types
6
+
7
+ ```ts
8
+ import type { ICDPSession } from './cdp-session.js';
9
+ export interface ReadResult {
10
+ content: string;
11
+ totalLines: number;
12
+ startLine: number;
13
+ endLine: number;
14
+ }
15
+ export interface SearchMatch {
16
+ url: string;
17
+ lineNumber: number;
18
+ lineContent: string;
19
+ }
20
+ export interface EditResult {
21
+ success: boolean;
22
+ stackChanged?: boolean;
23
+ }
24
+ /**
25
+ * A class for viewing and editing web page scripts via Chrome DevTools Protocol.
26
+ * Provides a Claude Code-like interface: list, read, edit, grep.
27
+ *
28
+ * Edits are in-memory only and persist until page reload. They modify the running
29
+ * V8 instance but are not saved to disk or server.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * const cdp = await getCDPSession({ page })
34
+ * const editor = new Editor({ cdp })
35
+ * await editor.enable()
36
+ *
37
+ * // List available scripts
38
+ * const scripts = editor.list({ search: 'app' })
39
+ *
40
+ * // Read a script
41
+ * const { content } = await editor.read({ url: 'https://example.com/app.js' })
42
+ *
43
+ * // Edit a script
44
+ * await editor.edit({
45
+ * url: 'https://example.com/app.js',
46
+ * oldString: 'console.log("old")',
47
+ * newString: 'console.log("new")'
48
+ * })
49
+ * ```
50
+ */
51
+ export declare class Editor {
52
+ private cdp;
53
+ private enabled;
54
+ private scripts;
55
+ private stylesheets;
56
+ private sourceCache;
57
+ constructor({ cdp }: {
58
+ cdp: ICDPSession;
59
+ });
60
+ private setupEventListeners;
61
+ /**
62
+ * Enables the editor. Must be called before other methods.
63
+ * Scripts are collected from Debugger.scriptParsed events.
64
+ * Reload the page after enabling to capture all scripts.
65
+ */
66
+ enable(): Promise<void>;
67
+ private getIdByUrl;
68
+ /**
69
+ * Lists available script and stylesheet URLs. Use pattern to filter by regex.
70
+ * Automatically enables the editor if not already enabled.
71
+ *
72
+ * @param options - Options
73
+ * @param options.pattern - Optional regex to filter URLs
74
+ * @returns Array of URLs
75
+ *
76
+ * @example
77
+ * ```ts
78
+ * // List all scripts and stylesheets
79
+ * const urls = await editor.list()
80
+ *
81
+ * // List only JS files
82
+ * const jsFiles = await editor.list({ pattern: /\.js/ })
83
+ *
84
+ * // List only CSS files
85
+ * const cssFiles = await editor.list({ pattern: /\.css/ })
86
+ *
87
+ * // Search for specific scripts
88
+ * const appScripts = await editor.list({ pattern: /app/ })
89
+ * ```
90
+ */
91
+ list({ pattern }?: {
92
+ pattern?: RegExp;
93
+ }): Promise<string[]>;
94
+ /**
95
+ * Reads a script or stylesheet's source code by URL.
96
+ * Returns line-numbered content like Claude Code's Read tool.
97
+ * For inline scripts, use the `inline://` URL from list() or grep().
98
+ *
99
+ * @param options - Options
100
+ * @param options.url - Script or stylesheet URL (inline scripts have `inline://{id}` URLs)
101
+ * @param options.offset - Line number to start from (0-based, default 0)
102
+ * @param options.limit - Number of lines to return (default 2000)
103
+ * @returns Content with line numbers, total lines, and range info
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * // Read by URL
108
+ * const { content, totalLines } = await editor.read({
109
+ * url: 'https://example.com/app.js'
110
+ * })
111
+ *
112
+ * // Read a CSS file
113
+ * const { content } = await editor.read({ url: 'https://example.com/styles.css' })
114
+ *
115
+ * // Read lines 100-200
116
+ * const { content } = await editor.read({
117
+ * url: 'https://example.com/app.js',
118
+ * offset: 100,
119
+ * limit: 100
120
+ * })
121
+ * ```
122
+ */
123
+ read({ url, offset, limit }: {
124
+ url: string;
125
+ offset?: number;
126
+ limit?: number;
127
+ }): Promise<ReadResult>;
128
+ private getSource;
129
+ /**
130
+ * Edits a script or stylesheet by replacing oldString with newString.
131
+ * Like Claude Code's Edit tool - performs exact string replacement.
132
+ *
133
+ * @param options - Options
134
+ * @param options.url - Script or stylesheet URL (inline scripts have `inline://{id}` URLs)
135
+ * @param options.oldString - Exact string to find and replace
136
+ * @param options.newString - Replacement string
137
+ * @param options.dryRun - If true, validate without applying (default false)
138
+ * @returns Result with success status
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * // Replace a string in JS
143
+ * await editor.edit({
144
+ * url: 'https://example.com/app.js',
145
+ * oldString: 'const DEBUG = false',
146
+ * newString: 'const DEBUG = true'
147
+ * })
148
+ *
149
+ * // Edit CSS
150
+ * await editor.edit({
151
+ * url: 'https://example.com/styles.css',
152
+ * oldString: 'color: red',
153
+ * newString: 'color: blue'
154
+ * })
155
+ * ```
156
+ */
157
+ edit({ url, oldString, newString, dryRun, }: {
158
+ url: string;
159
+ oldString: string;
160
+ newString: string;
161
+ dryRun?: boolean;
162
+ }): Promise<EditResult>;
163
+ private setSource;
164
+ /**
165
+ * Searches for a regex across all scripts and stylesheets.
166
+ * Like Claude Code's Grep tool - returns matching lines with context.
167
+ *
168
+ * @param options - Options
169
+ * @param options.regex - Regular expression to search for in file contents
170
+ * @param options.pattern - Optional regex to filter which URLs to search
171
+ * @returns Array of matches with url, line number, and line content
172
+ *
173
+ * @example
174
+ * ```ts
175
+ * // Search all scripts and stylesheets for "color"
176
+ * const matches = await editor.grep({ regex: /color/ })
177
+ *
178
+ * // Search only CSS files
179
+ * const matches = await editor.grep({
180
+ * regex: /background-color/,
181
+ * pattern: /\.css/
182
+ * })
183
+ *
184
+ * // Regex search for console methods in JS
185
+ * const matches = await editor.grep({
186
+ * regex: /console\.(log|error|warn)/,
187
+ * pattern: /\.js/
188
+ * })
189
+ * ```
190
+ */
191
+ grep({ regex, pattern }: {
192
+ regex: RegExp;
193
+ pattern?: RegExp;
194
+ }): Promise<SearchMatch[]>;
195
+ /**
196
+ * Writes entire content to a script or stylesheet, replacing all existing code.
197
+ * Use with caution - prefer edit() for targeted changes.
198
+ *
199
+ * @param options - Options
200
+ * @param options.url - Script or stylesheet URL (inline scripts have `inline://{id}` URLs)
201
+ * @param options.content - New content
202
+ * @param options.dryRun - If true, validate without applying (default false, only works for JS)
203
+ */
204
+ write({ url, content, dryRun }: {
205
+ url: string;
206
+ content: string;
207
+ dryRun?: boolean;
208
+ }): Promise<EditResult>;
209
+ }
210
+ ```
211
+
212
+ ## Examples
213
+
214
+ ```ts
215
+ import { page, getCDPSession, createEditor, console } from './debugger-examples-types.js'
216
+
217
+ // Example: List available scripts
218
+ async function listScripts() {
219
+ const cdp = await getCDPSession({ page })
220
+ const editor = createEditor({ cdp })
221
+ await editor.enable()
222
+
223
+ const scripts = editor.list({ pattern: /app/ })
224
+ console.log(scripts)
225
+ }
226
+
227
+ // Example: Read a script with line numbers
228
+ async function readScript() {
229
+ const cdp = await getCDPSession({ page })
230
+ const editor = createEditor({ cdp })
231
+ await editor.enable()
232
+
233
+ const { content, totalLines } = await editor.read({
234
+ url: 'https://example.com/app.js',
235
+ })
236
+ console.log('Total lines:', totalLines)
237
+ console.log(content)
238
+
239
+ const { content: partial } = await editor.read({
240
+ url: 'https://example.com/app.js',
241
+ offset: 100,
242
+ limit: 50,
243
+ })
244
+ console.log(partial)
245
+ }
246
+
247
+ // Example: Edit a script (exact string replacement)
248
+ async function editScript() {
249
+ const cdp = await getCDPSession({ page })
250
+ const editor = createEditor({ cdp })
251
+ await editor.enable()
252
+
253
+ await editor.edit({
254
+ url: 'https://example.com/app.js',
255
+ oldString: 'const DEBUG = false',
256
+ newString: 'const DEBUG = true',
257
+ })
258
+
259
+ const dryRunResult = await editor.edit({
260
+ url: 'https://example.com/app.js',
261
+ oldString: 'old code',
262
+ newString: 'new code',
263
+ dryRun: true,
264
+ })
265
+ console.log('Dry run result:', dryRunResult)
266
+ }
267
+
268
+ // Example: Search across all scripts
269
+ async function searchScripts() {
270
+ const cdp = await getCDPSession({ page })
271
+ const editor = createEditor({ cdp })
272
+ await editor.enable()
273
+
274
+ const matches = await editor.grep({ regex: /console\.log/ })
275
+ console.log(matches)
276
+
277
+ const todoMatches = await editor.grep({
278
+ regex: /TODO|FIXME/i,
279
+ pattern: /app/,
280
+ })
281
+ console.log(todoMatches)
282
+ }
283
+
284
+ // Example: Write entire script content
285
+ async function writeScript() {
286
+ const cdp = await getCDPSession({ page })
287
+ const editor = createEditor({ cdp })
288
+ await editor.enable()
289
+
290
+ const { content } = await editor.read({ url: 'https://example.com/app.js' })
291
+ const newContent = content.replace(/console\.log/g, 'console.debug')
292
+
293
+ await editor.write({
294
+ url: 'https://example.com/app.js',
295
+ content: newContent,
296
+ })
297
+ }
298
+
299
+ // Example: Edit an inline script (scripts without URL get inline://{id} URLs)
300
+ async function editInlineScript() {
301
+ const cdp = await getCDPSession({ page })
302
+ const editor = createEditor({ cdp })
303
+ await editor.enable()
304
+
305
+ const matches = await editor.grep({ regex: /myFunction/ })
306
+ if (matches.length > 0) {
307
+ const { url } = matches[0]
308
+ console.log('Found in:', url)
309
+
310
+ await editor.edit({
311
+ url,
312
+ oldString: 'return false',
313
+ newString: 'return true',
314
+ })
315
+ }
316
+ }
317
+
318
+ // Example: List and read CSS stylesheets
319
+ async function readStylesheet() {
320
+ const cdp = await getCDPSession({ page })
321
+ const editor = createEditor({ cdp })
322
+ await editor.enable()
323
+
324
+ const stylesheets = await editor.list({ pattern: /\.css/ })
325
+ console.log('Stylesheets:', stylesheets)
326
+
327
+ if (stylesheets.length > 0) {
328
+ const { content, totalLines } = await editor.read({
329
+ url: stylesheets[0],
330
+ })
331
+ console.log('Total lines:', totalLines)
332
+ console.log(content)
333
+ }
334
+ }
335
+
336
+ // Example: Edit a CSS stylesheet
337
+ async function editStylesheet() {
338
+ const cdp = await getCDPSession({ page })
339
+ const editor = createEditor({ cdp })
340
+ await editor.enable()
341
+
342
+ await editor.edit({
343
+ url: 'https://example.com/styles.css',
344
+ oldString: 'color: red',
345
+ newString: 'color: blue',
346
+ })
347
+ }
348
+
349
+ // Example: Search CSS for specific properties
350
+ async function searchStyles() {
351
+ const cdp = await getCDPSession({ page })
352
+ const editor = createEditor({ cdp })
353
+ await editor.enable()
354
+
355
+ const matches = await editor.grep({
356
+ regex: /background-color/,
357
+ pattern: /\.css/,
358
+ })
359
+ console.log(matches)
360
+ }
361
+
362
+ export { listScripts, readScript, editScript, searchScripts, writeScript, editInlineScript, readStylesheet, editStylesheet, searchStyles }
363
+
364
+ ```
@@ -0,0 +1,11 @@
1
+ declare function listScripts(): Promise<void>;
2
+ declare function readScript(): Promise<void>;
3
+ declare function editScript(): Promise<void>;
4
+ declare function searchScripts(): Promise<void>;
5
+ declare function writeScript(): Promise<void>;
6
+ declare function editInlineScript(): Promise<void>;
7
+ declare function readStylesheet(): Promise<void>;
8
+ declare function editStylesheet(): Promise<void>;
9
+ declare function searchStyles(): Promise<void>;
10
+ export { listScripts, readScript, editScript, searchScripts, writeScript, editInlineScript, readStylesheet, editStylesheet, searchStyles };
11
+ //# sourceMappingURL=editor-examples.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editor-examples.d.ts","sourceRoot":"","sources":["../src/editor-examples.ts"],"names":[],"mappings":"AAGA,iBAAe,WAAW,kBAOzB;AAGD,iBAAe,UAAU,kBAiBxB;AAGD,iBAAe,UAAU,kBAkBxB;AAGD,iBAAe,aAAa,kBAa3B;AAGD,iBAAe,WAAW,kBAYzB;AAGD,iBAAe,gBAAgB,kBAgB9B;AAGD,iBAAe,cAAc,kBAe5B;AAGD,iBAAe,cAAc,kBAU5B;AAGD,iBAAe,YAAY,kBAU1B;AAED,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,gBAAgB,EAAE,cAAc,EAAE,cAAc,EAAE,YAAY,EAAE,CAAA"}
@@ -0,0 +1,124 @@
1
+ import { page, getCDPSession, createEditor, console } from './debugger-examples-types.js';
2
+ // Example: List available scripts
3
+ async function listScripts() {
4
+ const cdp = await getCDPSession({ page });
5
+ const editor = createEditor({ cdp });
6
+ await editor.enable();
7
+ const scripts = editor.list({ pattern: /app/ });
8
+ console.log(scripts);
9
+ }
10
+ // Example: Read a script with line numbers
11
+ async function readScript() {
12
+ const cdp = await getCDPSession({ page });
13
+ const editor = createEditor({ cdp });
14
+ await editor.enable();
15
+ const { content, totalLines } = await editor.read({
16
+ url: 'https://example.com/app.js',
17
+ });
18
+ console.log('Total lines:', totalLines);
19
+ console.log(content);
20
+ const { content: partial } = await editor.read({
21
+ url: 'https://example.com/app.js',
22
+ offset: 100,
23
+ limit: 50,
24
+ });
25
+ console.log(partial);
26
+ }
27
+ // Example: Edit a script (exact string replacement)
28
+ async function editScript() {
29
+ const cdp = await getCDPSession({ page });
30
+ const editor = createEditor({ cdp });
31
+ await editor.enable();
32
+ await editor.edit({
33
+ url: 'https://example.com/app.js',
34
+ oldString: 'const DEBUG = false',
35
+ newString: 'const DEBUG = true',
36
+ });
37
+ const dryRunResult = await editor.edit({
38
+ url: 'https://example.com/app.js',
39
+ oldString: 'old code',
40
+ newString: 'new code',
41
+ dryRun: true,
42
+ });
43
+ console.log('Dry run result:', dryRunResult);
44
+ }
45
+ // Example: Search across all scripts
46
+ async function searchScripts() {
47
+ const cdp = await getCDPSession({ page });
48
+ const editor = createEditor({ cdp });
49
+ await editor.enable();
50
+ const matches = await editor.grep({ regex: /console\.log/ });
51
+ console.log(matches);
52
+ const todoMatches = await editor.grep({
53
+ regex: /TODO|FIXME/i,
54
+ pattern: /app/,
55
+ });
56
+ console.log(todoMatches);
57
+ }
58
+ // Example: Write entire script content
59
+ async function writeScript() {
60
+ const cdp = await getCDPSession({ page });
61
+ const editor = createEditor({ cdp });
62
+ await editor.enable();
63
+ const { content } = await editor.read({ url: 'https://example.com/app.js' });
64
+ const newContent = content.replace(/console\.log/g, 'console.debug');
65
+ await editor.write({
66
+ url: 'https://example.com/app.js',
67
+ content: newContent,
68
+ });
69
+ }
70
+ // Example: Edit an inline script (scripts without URL get inline://{id} URLs)
71
+ async function editInlineScript() {
72
+ const cdp = await getCDPSession({ page });
73
+ const editor = createEditor({ cdp });
74
+ await editor.enable();
75
+ const matches = await editor.grep({ regex: /myFunction/ });
76
+ if (matches.length > 0) {
77
+ const { url } = matches[0];
78
+ console.log('Found in:', url);
79
+ await editor.edit({
80
+ url,
81
+ oldString: 'return false',
82
+ newString: 'return true',
83
+ });
84
+ }
85
+ }
86
+ // Example: List and read CSS stylesheets
87
+ async function readStylesheet() {
88
+ const cdp = await getCDPSession({ page });
89
+ const editor = createEditor({ cdp });
90
+ await editor.enable();
91
+ const stylesheets = await editor.list({ pattern: /\.css/ });
92
+ console.log('Stylesheets:', stylesheets);
93
+ if (stylesheets.length > 0) {
94
+ const { content, totalLines } = await editor.read({
95
+ url: stylesheets[0],
96
+ });
97
+ console.log('Total lines:', totalLines);
98
+ console.log(content);
99
+ }
100
+ }
101
+ // Example: Edit a CSS stylesheet
102
+ async function editStylesheet() {
103
+ const cdp = await getCDPSession({ page });
104
+ const editor = createEditor({ cdp });
105
+ await editor.enable();
106
+ await editor.edit({
107
+ url: 'https://example.com/styles.css',
108
+ oldString: 'color: red',
109
+ newString: 'color: blue',
110
+ });
111
+ }
112
+ // Example: Search CSS for specific properties
113
+ async function searchStyles() {
114
+ const cdp = await getCDPSession({ page });
115
+ const editor = createEditor({ cdp });
116
+ await editor.enable();
117
+ const matches = await editor.grep({
118
+ regex: /background-color/,
119
+ pattern: /\.css/,
120
+ });
121
+ console.log(matches);
122
+ }
123
+ export { listScripts, readScript, editScript, searchScripts, writeScript, editInlineScript, readStylesheet, editStylesheet, searchStyles };
124
+ //# sourceMappingURL=editor-examples.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editor-examples.js","sourceRoot":"","sources":["../src/editor-examples.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAA;AAEzF,kCAAkC;AAClC,KAAK,UAAU,WAAW;IACxB,MAAM,GAAG,GAAG,MAAM,aAAa,CAAC,EAAE,IAAI,EAAE,CAAC,CAAA;IACzC,MAAM,MAAM,GAAG,YAAY,CAAC,EAAE,GAAG,EAAE,CAAC,CAAA;IACpC,MAAM,MAAM,CAAC,MAAM,EAAE,CAAA;IAErB,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAA;IAC/C,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;AACtB,CAAC;AAED,2CAA2C;AAC3C,KAAK,UAAU,UAAU;IACvB,MAAM,GAAG,GAAG,MAAM,aAAa,CAAC,EAAE,IAAI,EAAE,CAAC,CAAA;IACzC,MAAM,MAAM,GAAG,YAAY,CAAC,EAAE,GAAG,EAAE,CAAC,CAAA;IACpC,MAAM,MAAM,CAAC,MAAM,EAAE,CAAA;IAErB,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC;QAChD,GAAG,EAAE,4BAA4B;KAClC,CAAC,CAAA;IACF,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,UAAU,CAAC,CAAA;IACvC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IAEpB,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC;QAC7C,GAA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