Skip to content

Instantly share code, notes, and snippets.

@gicrisf
Last active July 19, 2024 18:11
Show Gist options
  • Select an option

  • Save gicrisf/1c6495d59ac50cddbc75c45a85f7393c to your computer and use it in GitHub Desktop.

Select an option

Save gicrisf/1c6495d59ac50cddbc75c45a85f7393c to your computer and use it in GitHub Desktop.
Run puppeteer with only promises in a clean way
var puppeteer = require("puppeteer");
(() => {
let browser;
let page;
puppeteer
// pass `{ headless: false }` if you want to see the browser
.launch()
.then(it =>
new Promise
// Move the browser in the let outside
(res => res (browser = it)))
.then(() =>
new Promise
// Open a new page
(res => res(browser.newPage())))
.then(it =>
new Promise
// Move the new page outside
(res => res(page = it)))
.then(() =>
new Promise
// Open a web page
(res => res (page.goto('https://developer.chrome.com/'))))
.then(it =>
new Promise
// Finally, close the browser
(res => res(browser.close())));
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment