Puppeteer waitForBackboneEvent()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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