Bug 1931425 - Limit how often moz-label's #setStyles runs r=reusable-components-revie...
[gecko.git] / remote / test / puppeteer / examples / custom-event.js
blob960bca34eed8763631a77805eacbe185e46245b6
1 /**
2 * @license
3 * Copyright 2017 Google Inc.
4 * SPDX-License-Identifier: Apache-2.0
5 */
7 'use strict';
9 const puppeteer = require('puppeteer');
11 (async () => {
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 || '');
18 });
20 /**
21 * Attach an event listener to page to capture a custom event on page load/navigation.
22 * @param {string} type Event name.
23 * @returns {!Promise}
25 function listenFor(type) {
26 return page.evaluateOnNewDocument(type => {
27 document.addEventListener(type, e => {
28 window.onCustomEvent({type, detail: e.detail});
29 });
30 }, type);
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',
37 });
39 await browser.close();
40 })();