Skip to content

Instantly share code, notes, and snippets.

@radiofrequency
Last active April 25, 2018 15:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save radiofrequency/f8d0facb45c4a7c97dfc526609543ee8 to your computer and use it in GitHub Desktop.
Save radiofrequency/f8d0facb45c4a7c97dfc526609543ee8 to your computer and use it in GitHub Desktop.
Puppeteer waitForBackboneEvent()
const puppeteer = require('puppeteer');
(async() => {
const browser = await puppeteer.launch({
ignoreHTTPSErrors: true,
slowMo: 100,
headless: false,
args: ["--disable-notifications", "--ash-host-window-bounds 100+200-300x400"]
});
page.on('console', msg => {
console.log(msg.text)
});
await page.goto("https://www.datememe.com", {
waitUntil: "networkidle2"
}).catch(function(err) {
console.log("reject", err);
})
var waitForEvent = async function(event_name) {
await page.evaluate(event_name => {
return new Promise((resolve, reject) => {
if (!window.vents) reject("no events found");
console.log("waiting for event", event_name);
window.vents.on(event_name, function(msg) {
window.vents.off(event_name);
resolve();
});
});
}, event_name);
}
await waitForEvent("something");
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment