codecamp

Puppeteer 对话

class:dialog

class: Dialog v0.9.0 Dialog 对象通过 'dialog' 事件的页面分发。 一个使用 Dialog 类的例子:

const puppeteer = require('puppeteer');
puppeteer.launch().then(async browser = >{
    const page = await browser.newPage();
    page.on('dialog', async dialog = >{
        console.log(dialog.message());
        await dialog.dismiss();
        await browser.close();
    });
    page.evaluate(() = >alert('1'));
});

Methods

  • dialog.accept([promptText])v0.9.0
  • dialog.defaultValue()v0.9.0
  • dialog.dismiss()v0.9.0
  • dialog.message()v0.9.0
  • dialog.type()v0.9.0

Methods

dialog.accept([promptText])v0.9.0

  • promptText <string> 提示中输入的文本。 如果对话框的类型不提示,不会产生任何影响。
  • returns: <Promise> Promise which resolves when the dialog has been accepted.

dialog.defaultValue()v0.9.0

  • returns: <string> 如果对话框出现提示,则返回默认提示值。 否则,返回空字符串。

dialog.dismiss()v0.9.0

  • returns: <Promise> Promise which resolves when the dialog has been dismissed.

dialog.message()v0.9.0

  • returns: <string> 显示在对话框中的信息。

dialog.type()v0.9.0

  • returns: <string> 对话框类型,可以是 alert ,beforeunload ,confirm 或 prompt 中的一个。
Puppeteer 追踪
Puppeteer 控制台消息
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }