Git Product home page Git Product logo

Comments (5)

dgozman avatar dgozman commented on April 28, 2024 1

I think onFoo is a nice way to subscribe to events. We use it in our testing harnesses a lot.

page.onAlert(message => {
  console.log(message);
});

from puppeteer.

ebidel avatar ebidel commented on April 28, 2024 1

I like it.

from puppeteer.

aslushnikov avatar aslushnikov commented on April 28, 2024

@dgozman: the 'onAlert', 'onPrompt" and 'onConfirm' setters feel foreign to the rest of the API.
For example:

var Browser = require('puppeteer').Browser;
var browser = new Browser();
browser.newPage().then(async page => {
    await page.setViewportSize({width: 1000, height: 1000});
    await page.navigate('http://example.com');
    page.onAlert = message => {
        console.log(message);
    };
    page.onConfirm = message => {
        console.log(message);
        return true;
    }
});

How about having page.setAlertCallback instead?
Will look like this:

var Browser = require('puppeteer').Browser;
var browser = new Browser();
browser.newPage().then(async page => {
    await page.setViewportSize({width: 1000, height: 1000});
    await page.navigate('http://example.com');
    page.setAlertCallback(message => {
        console.log(message);
    });
    page.setConfirmCallback(message => {
        console.log(message);
        return true;
    });
});

I like setAlertCallback - it is simple and consistent with the rest of the api. What do you think?

from puppeteer.

aslushnikov avatar aslushnikov commented on April 28, 2024

So we've sat with @paulirish and get a feeling of a few options here.

We don't like the following, cause it makes it hard to dismiss all the dialogs:

page.on('alert', message => {
   console.log(message);
});

We don't like the phantom's way, 'cause it's weird:

page.onPrompt = message => {
   return {
     text, success
   }
};

We don't like the dialog callback, 'cause it's too verbose:

page.setDialogCallback(dialog => {
   dialog.accept()
   dialog.type()
   dialog.dismiss();
});

The thing which we liked most is the event with dialog class:

page.on('dialog', dialog => {
   dialog.type // 'alert', 'confirm', 'prompt', 'beforeunload'
   dialog.accept(); // takes optional string
   dialog.dismiss();
});

How do you guys feel? @dgozman @ebidel

from puppeteer.

aslushnikov avatar aslushnikov commented on April 28, 2024

For the record: dialog handling is currently suffering on headless due to the crbug.com/718235. This bug results in all the javascript dialogs being dismissed on headless.

from puppeteer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.