presidium 3.3.2 → 3.4.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/GoogleChromeDevTools.js +127 -5
- package/GoogleChromeForTesting.js +10 -2
- package/package.json +1 -1
package/GoogleChromeDevTools.js
CHANGED
|
@@ -12,7 +12,7 @@ function getId() {
|
|
|
12
12
|
*
|
|
13
13
|
* @docs
|
|
14
14
|
* ```coffeescript [specscript]
|
|
15
|
-
* sendRequestJSON(payload
|
|
15
|
+
* sendRequestJSON(payload object) -> data Promise<Object>
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
18
|
async function sendRequestJSON(payload) {
|
|
@@ -23,13 +23,13 @@ async function sendRequestJSON(payload) {
|
|
|
23
23
|
|
|
24
24
|
const handler = function (message) {
|
|
25
25
|
const data = JSON.parse(message.toString('utf8'))
|
|
26
|
-
if (data.id == id) {
|
|
26
|
+
if (data.id == payload.id) {
|
|
27
27
|
resolve(data)
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
this.websocket.on('message', handler)
|
|
32
|
-
this.websocket.send(payload)
|
|
32
|
+
this.websocket.send(JSON.stringify(payload))
|
|
33
33
|
|
|
34
34
|
const data = await promise
|
|
35
35
|
this.websocket.removeListener('message', handler)
|
|
@@ -51,12 +51,12 @@ async function sendRequestJSON(payload) {
|
|
|
51
51
|
async function _Method(method, { sessionId, ...params }) {
|
|
52
52
|
const id = getId()
|
|
53
53
|
|
|
54
|
-
const payload =
|
|
54
|
+
const payload = {
|
|
55
55
|
sessionId: sessionId ?? this.sessionId,
|
|
56
56
|
id,
|
|
57
57
|
method,
|
|
58
58
|
params,
|
|
59
|
-
}
|
|
59
|
+
}
|
|
60
60
|
|
|
61
61
|
const data = await sendRequestJSON.call(this, payload)
|
|
62
62
|
|
|
@@ -141,6 +141,33 @@ class GoogleChromeDevToolsPage {
|
|
|
141
141
|
this.websocket = websocket
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
+
/**
|
|
145
|
+
* @name Page.enable
|
|
146
|
+
*
|
|
147
|
+
* @docs
|
|
148
|
+
* ```coffeescript [specscript]
|
|
149
|
+
* Page.enable(options {
|
|
150
|
+
* sessionId: string,
|
|
151
|
+
* }) -> data Promise<{}>
|
|
152
|
+
* ```
|
|
153
|
+
*
|
|
154
|
+
* Enables Page events for the current target.
|
|
155
|
+
*
|
|
156
|
+
* Arguments:
|
|
157
|
+
* * `options`
|
|
158
|
+
* * `sessionId` - the session ID.
|
|
159
|
+
*
|
|
160
|
+
* Return:
|
|
161
|
+
* * `data` - promise of an empty object.
|
|
162
|
+
*
|
|
163
|
+
* ```javascript
|
|
164
|
+
* await googleChromeDevTools.Page.enable()
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
enable(options = {}) {
|
|
168
|
+
return _Method.call(this, 'Page.enable', options)
|
|
169
|
+
}
|
|
170
|
+
|
|
144
171
|
/**
|
|
145
172
|
* @name Page.navigate
|
|
146
173
|
*
|
|
@@ -176,6 +203,98 @@ class GoogleChromeDevToolsPage {
|
|
|
176
203
|
navigate(options = {}) {
|
|
177
204
|
return _Method.call(this, 'Page.navigate', options)
|
|
178
205
|
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* @name Page.handleJavaScriptDialog
|
|
209
|
+
*
|
|
210
|
+
* @docs
|
|
211
|
+
* ```coffeescript [specscript]
|
|
212
|
+
* Page.handleJavaScriptDialog(options {
|
|
213
|
+
* sessionId: string,
|
|
214
|
+
* accept: boolean,
|
|
215
|
+
* promptText: string,
|
|
216
|
+
* }) -> data Promise<{}>
|
|
217
|
+
* ```
|
|
218
|
+
*
|
|
219
|
+
* Handles (accepts or dismisses) a JavaScript initiated dialog (alert, confirm, prompt, or onbeforeunload).
|
|
220
|
+
*
|
|
221
|
+
* Arguments:
|
|
222
|
+
* * `options`
|
|
223
|
+
* * `sessionId` - the session ID.
|
|
224
|
+
* * `accept` - whether to accept or dismiss the dialog.
|
|
225
|
+
* * `promptText` - the text to enter into the dialog prompt before accepting.
|
|
226
|
+
*
|
|
227
|
+
* Return:
|
|
228
|
+
* * `data` - promise of an empty object.
|
|
229
|
+
*
|
|
230
|
+
* ```javascript
|
|
231
|
+
* await googleChromeDevTools.Page.handleJavaScriptDialog({
|
|
232
|
+
* url: 'http://localhost:3000/',
|
|
233
|
+
* })
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
handleJavaScriptDialog(options = {}) {
|
|
237
|
+
return _Method.call(this, 'Page.handleJavaScriptDialog', options)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* @name Event: Page.javascriptDialogOpening
|
|
242
|
+
*
|
|
243
|
+
* @docs
|
|
244
|
+
* ```coffeescript [specscript]
|
|
245
|
+
* emit('Page.javascriptDialogOpening', data {
|
|
246
|
+
* url: string,
|
|
247
|
+
* frameId: string,
|
|
248
|
+
* message: string,
|
|
249
|
+
* type: 'alert'|'confirm'|'prompt'|'beforeunload',
|
|
250
|
+
* hasBrowserHandler: boolean,
|
|
251
|
+
* })
|
|
252
|
+
* ```
|
|
253
|
+
*
|
|
254
|
+
* The `DOM.attributeModified` event. Emitted when an attribute of an element is modified.
|
|
255
|
+
*
|
|
256
|
+
* Event Data:
|
|
257
|
+
* `data`
|
|
258
|
+
* * `url` - the frame URL.
|
|
259
|
+
* * `frameId` - the frame ID.
|
|
260
|
+
* * `message` - message displayed by the dialog.
|
|
261
|
+
* * `type` - the dialog type.
|
|
262
|
+
* * `hasBrowserHandler` - whether the browser is capable of acting on the given dialog.
|
|
263
|
+
*
|
|
264
|
+
* ```javascript
|
|
265
|
+
* googleChromeDevTools.on('Page.javascriptDialogOpening', data => {
|
|
266
|
+
* console.log('dialog opening', data)
|
|
267
|
+
* })
|
|
268
|
+
* ```
|
|
269
|
+
*/
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* @name Event: Page.javascriptDialogClosed
|
|
273
|
+
*
|
|
274
|
+
* @docs
|
|
275
|
+
* ```coffeescript [specscript]
|
|
276
|
+
* emit('Page.javascriptDialogClosed', data {
|
|
277
|
+
* frameId: string,
|
|
278
|
+
* result: boolean,
|
|
279
|
+
* userInput: string,
|
|
280
|
+
* })
|
|
281
|
+
* ```
|
|
282
|
+
*
|
|
283
|
+
* The `DOM.attributeModified` event. Emitted when an attribute of an element is modified.
|
|
284
|
+
*
|
|
285
|
+
* Event Data:
|
|
286
|
+
* `data`
|
|
287
|
+
* * `frameId` - the frame ID.
|
|
288
|
+
* * `result` - whether the dialog was confirmed.
|
|
289
|
+
* * `userInput` - the user input if the dialog was a prompt.
|
|
290
|
+
*
|
|
291
|
+
* ```javascript
|
|
292
|
+
* googleChromeDevTools.on('Page.javascriptDialogClosed', data => {
|
|
293
|
+
* console.log('dialog closed', data)
|
|
294
|
+
* })
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
|
|
179
298
|
}
|
|
180
299
|
|
|
181
300
|
class GoogleChromeDevToolsDOM {
|
|
@@ -371,6 +490,7 @@ class GoogleChromeDevToolsDOM {
|
|
|
371
490
|
* DOM.describeNode(options {
|
|
372
491
|
* sessionId: string,
|
|
373
492
|
* nodeId: string,
|
|
493
|
+
* depth: number,
|
|
374
494
|
* }) -> data Promise<{
|
|
375
495
|
* node: CDPDOM.Node,
|
|
376
496
|
* }>
|
|
@@ -382,6 +502,7 @@ class GoogleChromeDevToolsDOM {
|
|
|
382
502
|
* * `options`
|
|
383
503
|
* * `sessionId` - the session ID.
|
|
384
504
|
* * `nodeId` - the ID of the node to describe.
|
|
505
|
+
* * `depth` - the maximum depth of the subtree. Defaults to `1`. Use `-1` for the entire subtree.
|
|
385
506
|
*
|
|
386
507
|
* Return:
|
|
387
508
|
* * `data`
|
|
@@ -1052,6 +1173,7 @@ class GoogleChromeDevTools extends EventEmitter {
|
|
|
1052
1173
|
})
|
|
1053
1174
|
await this.googleChromeForTesting.init()
|
|
1054
1175
|
|
|
1176
|
+
console.log('initializing websocket with devtoolsUrl:', this.googleChromeForTesting.devtoolsUrl)
|
|
1055
1177
|
this.websocket = new WebSocket(this.googleChromeForTesting.devtoolsUrl, {
|
|
1056
1178
|
offerPerMessageDeflate: false,
|
|
1057
1179
|
})
|
|
@@ -267,8 +267,12 @@ class GoogleChromeForTesting {
|
|
|
267
267
|
const devtoolsUrlPromise = new Promise(_resolve => {
|
|
268
268
|
devtoolsUrlResolve = _resolve
|
|
269
269
|
})
|
|
270
|
-
|
|
271
|
-
|
|
270
|
+
|
|
271
|
+
const rl = readline.createInterface({
|
|
272
|
+
input: cmd.stderr,
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
rl.on('line', line => {
|
|
272
276
|
if (line.includes('DevTools listening on')) {
|
|
273
277
|
const devtoolsUrl = line.replace('DevTools listening on ', '')
|
|
274
278
|
devtoolsUrlResolve(devtoolsUrl)
|
|
@@ -288,6 +292,10 @@ class GoogleChromeForTesting {
|
|
|
288
292
|
process.exit(1)
|
|
289
293
|
})
|
|
290
294
|
|
|
295
|
+
cmd.on('exit', code => {
|
|
296
|
+
console.log(`${chromeFilepath} exited with code ${code}`)
|
|
297
|
+
})
|
|
298
|
+
|
|
291
299
|
process.on('SIGTERM', () => {
|
|
292
300
|
cmd.kill()
|
|
293
301
|
})
|