Define function/custom events to execute when loading and navigating the page

Source: Internet
Author: User
Tags define function

/** * 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.