puppeteer/experimental/puppeteer-firefox/lib/firefox/Dialog.js
Andrey Lushnikov 45ab3e0332
feat: introduce puppeteer-firefox (#3628)
This adds a proof-of-concept of `puppeteer-firefox`.
This consists of two parts:
- `//experimental/juggler` - patches to apply to Firefox.
- `//experimental/puppeteer-firefox` - front-end code to
be merged with Puppeteer.

As things become more stable, we'll gradually move it out of
the experimental folder.
2018-12-06 11:24:00 -08:00

58 lines
1.2 KiB
JavaScript

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};