3 * Copyright 2017 Google Inc.
4 * SPDX-License-Identifier: Apache-2.0
9 const puppeteer
= require('puppeteer');
12 const browser
= await puppeteer
.launch();
13 const page
= await browser
.newPage();
15 // Define a window.onCustomEvent function on the page.
16 await page
.exposeFunction('onCustomEvent', e
=> {
17 console
.log(`${e.type} fired`, e
.detail
|| '');
21 * Attach an event listener to page to capture a custom event on page load/navigation.
22 * @param {string} type Event name.
25 function listenFor(type
) {
26 return page
.evaluateOnNewDocument(type
=> {
27 document
.addEventListener(type
, e
=> {
28 window
.onCustomEvent({type
, detail
: e
.detail
});
33 await
listenFor('app-ready'); // Listen for "app-ready" custom event on page load.
35 await page
.goto('https://www.chromestatus.com/features', {
36 waitUntil
: 'networkidle0',
39 await browser
.close();