For examples, we should start running them through the linter and clean up the code a bit so they're consistent and using es6. e.g. use const/let
and a top-level async func to remove the mix of .then()
and async/await. I think that's less common to see.
For example, this:
var browser = new Browser({headless: false});
browser.newPage().then(async page => {
page.setRequestInterceptor(request => {
if (request.url.endsWith('.css'))
request.abort();
else
request.continue();
});
var success = await page.navigate(address);
if (!success)
console.log('Unable to load the address!');
browser.close();
to maybe to something like this:
(async () => {
const browser = new Browser({headless: false});
const page = await browser.newPage();
page.setRequestInterceptor(request => {
request.url.endsWith('.css') ? request.abort() : request.continue();
});
const success = await page.navigate(address);
if (!success) {
console.log('Unable to load the address!');
}
browser.close();
})();
Do we want to keep the phantom examples? They feel out of place.
I can't come up with a simple yet illustrative example for page.addBinding (former inPage callback).
However, documentation has a few examples which might be good enough.
Closing this for now.
P.S. Feel free to PR an example with page.addBinding
/ share an idea for it if any!
Most helpful comment
For examples, we should start running them through the linter and clean up the code a bit so they're consistent and using es6. e.g. use
const/let
and a top-level async func to remove the mix of.then()
and async/await. I think that's less common to see.For example, this:
to maybe to something like this: