-
Notifications
You must be signed in to change notification settings - Fork 9k
/
Dialog.js
57 lines (50 loc) · 1.17 KB
/
Dialog.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const {helper, assert, debugError} = require('./helper');
class Dialog {
constructor(client, payload) {
this._client = client;
this._dialogId = payload.dialogId;
this._type = payload.type;
this._message = payload.message;
this._handled = false;
this._defaultValue = payload.defaultValue || '';
}
/**
* @return {string}
*/
type() {
return this._type;
}
/**
* @return {string}
*/
message() {
return this._message;
}
/**
* @return {string}
*/
defaultValue() {
return this._defaultValue;
}
/**
* @param {string=} promptText
*/
async accept(promptText) {
assert(!this._handled, 'Cannot accept dialog which is already handled!');
this._handled = true;
await this._client.send('Page.handleDialog', {
dialogId: this._dialogId,
accept: true,
promptText: promptText
}).catch(debugError);
}
async dismiss() {
assert(!this._handled, 'Cannot dismiss dialog which is already handled!');
this._handled = true;
await this._client.send('Page.handleDialog', {
dialogId: this._dialogId,
accept: false
}).catch(debugError);
}
}
module.exports = {Dialog};