/** * Copyright by Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * You are not a use this file except in compliance with the License. * Obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * unless required by applic Able law or agreed to in writing, software * Distributed under the License are distributed on a "as is" BASIS, * without W Arranties or CONDITIONS of any KIND, either express OR implied. * See the License for the specific language governing permissions and * limitations under the License. */' use strict '; const puppeteer = require (' puppeteer ');(async () = {Const Browser = await puppeteer.launch (); Const PAGE = await browser.newpage ();//Define a window.oncustomevent function on the page. Await page.exposefunction (' oncustomevent ', E = {console.log (' ${e.type} fired ', E.detail | | ‘‘); });/** * Attach an Event listener to page to capture a custom event on page load/navigation. * @param {string} type Event name. * @return {! Promise} */function Listenfor (type) {return page.evaluateonnewdocument (type = {//function Document.addeventlistener to execute when defining page loading and navigation (type, E = = { Window.oncustomevent ({type, detail:e.detail}); }); }, type);} await listenfor (' App-ready '); Listen for "App-ready" the custom event on page load. Await Page.goto (' Https://www.chromestatus.com/features ', {waituntil: ' Networkidle0 '}); await Browser.close ();}) ();
Define function/custom events to execute when loading and navigating the page