Comments (5)
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.
I like it.
from puppeteer.
@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.
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.
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)
- [Bug]: Unable to bundle puppeteer script with wepack HOT 2
- [Feature]: Inserting a Audio and video Stream HOT 2
- PDF export error for chart and HTM amchart5 HOT 1
- [Bug]: Stuck at puppeteer.connect() HOT 2
- [Bug]: Even your example code is not working - SyntaxError: Cannot use import statement outside a module HOT 1
- [Feature]: Inserting a Audio and video Stream
- "[network.spec] network Page.authenticate should work" test is flaky HOT 1
- [Bug]: Browser gets disconnected in Docker without any errors HOT 28
- [Bug]: Failed to launch the browser process!\nchrome_crashpad_handler: --database is required HOT 2
- Docs: the index page for docs should not be a readme.md
- [Feature]: Accessing WebRTC peerConnection in puppeteer
- Force pushing to default branch HOT 1
- [Bug]: ERROR in DIGITALOCEAN APPLICATION PLATFORM HOT 2
- [Bug]: when accessing browser.targets() I don't get info about _targetInfo which have property like _targetInfo.title , _targetInfo.type... HOT 2
- [Bug]: Opening the extension popup.html using will return new empty popup without any data how to get popup.html within the context of a specific tab/website HOT 4
- [Bug]: Background is pink when using background: repeating-linear-gradient HOT 10
- [Bug]: Could not able to get the selectors when headless: true, but it is working with headless:false HOT 1
- [Bug]: Freezing when querying frames on certain websites HOT 11
- [Feature]: `Mouse.dragAndDrop` API not supported for WebDriver BiDi HOT 7
- Error: Attempted to use detached Frame HOT 15
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from puppeteer.