博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
定义页面加载和导航时要执行的函数/自定义事件
阅读量:4575 次
发布时间:2019-06-08

本文共 1591 字,大约阅读时间需要 5 分钟。

http://www.cnblogs.com/dolphinX/p/7715268.html---好文 /** * Copyright 2017 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES 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 => {//定义页面加载和导航时要执行的函数      document.addEventListener(type, e => {        window.onCustomEvent({type, detail: e.detail});      });    }, type);  }  await listenFor('app-ready'); // Listen for "app-ready" custom event on page load.  await page.goto('https://www.chromestatus.com/features', {waitUntil: 'networkidle0'});  await browser.close();})();

转载于:https://www.cnblogs.com/justart/p/9750360.html

你可能感兴趣的文章
Mysql主从配置,实现读写分离
查看>>
完整版本的停车场管理系统源代码带服务端+手机android客户端
查看>>
HTML标签(二)
查看>>
在weblogic下运行Python脚本
查看>>
短信开发技术总结--协议篇
查看>>
HashMap实现原理分析
查看>>
私有类方法
查看>>
java网络编程Socket通信详解
查看>>
为什么使用Nosql:Nosql和SQL的区别
查看>>
<转>DNS服务系列之二:DNS区域传送漏洞的安全案例
查看>>
LINUX中常用操作命令
查看>>
【android】动画效果研究(View)【1】
查看>>
(三)常用的数学函数
查看>>
生产信息集成分析平台(MIIAS V1.0) 概述
查看>>
学习进度——第十五周
查看>>
简谈-网络爬虫的几种常见类型
查看>>
File对象目录列表器
查看>>
(K)ubuntu上将分区格式化成NTFS格式
查看>>
mysql5.7二进制包安装方式
查看>>
装饰者模式——Java设计模式
查看>>