Headless Chrome
Headless Chrome
https://developers.google.com/web/updates/2017/04/headless-chrome
Puppeteer & SSR
https://developers.google.com/web/tools/puppeteer/articles/ssr

bug

"use strict";
/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2020-02-22
* @modified
*
* @description
* @augments
* @example
* @link
*
*/
const log = console.log;
const Koa = require('koa');
const app = new Koa();
const fs = require('fs');
const path = require('path');
const puppeteer = require('puppeteer');
const Poster = async (url) => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
// await page.emulate(devices['iPhone X']);
await page.goto(url);
await page.screenshot({
path: 'poster-template-ssr.png',
fullPage: true,
});
await browser.close();
}
// logger
app.use(async (ctx, next) => {
await next();
const rt = ctx.response.get('X-Response-Time');
log(`${ctx.method} ${ctx.url} - ${rt}`);
});
// x-response-time
app.use(async (ctx, next) => {
const start = Date.now();
await next();
const ms = Date.now() - start;
ctx.set('X-Response-Time', `${ms}ms`);
});
// response
app.use(async ctx => {
ctx.response.set("content-type", "text/html");
const html = fs.createReadStream('./index.html');
ctx.body = html;
// response html
const uid = 1234567;
const url = `http://localhost:3000/template/index.html?id=${uid}`;
await Poster(url);
});
app.listen(3000);
partly ok
"use strict";
/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2020-02-22
* @modified
*
* @description
* @augments
* @example
* @link
*
*/
const log = console.log;
const Koa = require('koa');
const app = new Koa();
const fs = require('fs');
const path = require('path');
const puppeteer = require('puppeteer');
const Poster = async (url) => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
// await page.emulate(devices['iPhone X']);
await page.goto(url);
await page.screenshot({
path: 'poster-template-ssr.png',
fullPage: true,
});
await browser.close();
}
// logger
app.use(async (ctx, next) => {
await next();
const rt = ctx.response.get('X-Response-Time');
log(`${ctx.method} ${ctx.url} - ${rt}`);
});
// x-response-time
app.use(async (ctx, next) => {
const start = Date.now();
await next();
const ms = Date.now() - start;
ctx.set('X-Response-Time', `${ms}ms`);
});
// response
app.use(async ctx => {
ctx.response.set("content-type", "text/html");
const html = fs.createReadStream('./index.html');
ctx.body = html;
// response html
const uid = 1234567;
const url = `http://localhost:3000/template/index.html?id=${uid}`;
// 连续监听,memory leak 抖动 bug
setTimeout(() => {
Poster(url);
}, 3000);
});
app.listen(3000);
full page scroll
https://alvarotrigo.com/fullPage/examples/apple.html
xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
Headless Chrome的更多相关文章
- Web自动化之Headless Chrome概览
Web自动化 这里所说的Web自动化是所有跟页面相关的自动化,比如页面爬取,数据抓取,页面内容检测,页面功能测试,页面加载性能测试,页面回归测试等等,当前主要由如下几种解决方式: 文本数据获取 这就是 ...
- Web自动化之Headless Chrome编码实战
API 概览 && 编码Tips 文档地址 github Chrome DevTools Protocol 协议本身的仓库 有问题可以在这里提issue github debugger ...
- puppeteer,新款headless chrome!
puppeteer puppeteer是一种谷歌开发的Headless Chrome,因为puppeteer的出现,业内许多自动化测试库停止维护,比如PhantomJS,Selenium IDE fo ...
- Web自动化之Headless Chrome测试框架集成
使用Selenium操作headless chrome 推荐 简介 WebDriver是一个W3C标准, 定义了一套检查和控制用户代理(比如浏览器)的远程控制接口,各大主流浏览器来实现这些接口以便调用 ...
- Web自动化之Headless Chrome开发工具库
命令行运行Headless Chrome Chrome 安装(需要带梯子) 下载地址 几个版本的比较 Chromium 不是Chrome,但Chrome的内容基本来源于Chromium,这个是开源的版 ...
- Headless Chrome:服务端渲染JS站点的一个方案【上篇】【翻译】
原文链接:https://developers.google.com/web/tools/puppeteer/articles/ssr 注:由于英文水平有限,没有逐字翻译,可以选择直接阅读原文 tip ...
- Headless Chrome:服务端渲染JS站点的一个方案【中篇】【翻译】
接上篇 防止重新渲染 其实说不对客户端代码做任何修改是忽悠人的.在我们的Express 应用中,通过Puppteer加载页面,提供给客户端响应,但是这个过程是有一些问题的. js脚本在服务端的Head ...
- Java 实现 HttpClients+jsoup,Jsoup,htmlunit,Headless Chrome 爬虫抓取数据
最近整理一下手头上搞过的一些爬虫,有HttpClients+jsoup,Jsoup,htmlunit,HeadlessChrome 一,HttpClients+jsoup,这是第一代比较low,很快就 ...
- PuppeteerSharp: 更友好的 Headless Chrome C# API
前端就有了对 headless 浏览器的需求,最多的应用场景有两个 UI 自动化测试:摆脱手工浏览点击页面确认功能模式 爬虫:解决页面内容异步加载等问题 也就有了很多杰出的实现,前端经常使用的莫过于 ...
- Puppeteer: 更友好的 Headless Chrome Node API
很早很早之前,前端就有了对 headless 浏览器的需求,最多的应用场景有两个 UI 自动化测试:摆脱手工浏览点击页面确认功能模式 爬虫:解决页面内容异步加载等问题 也就有了很多杰出的实现,前端经常 ...
随机推荐
- LOJ10078
CQOI 2005 重庆城里有 n 个车站,m 条双向公路连接其中的某些车站.每两个车站最多用一条公路连接,从任何一个车站出发都可以经过一条或者多条公路到达其他车站,但不同的路径需要花费的时间可能不同 ...
- ubuntu中如何安装selenium+chrome(headless)无界面浏览器?
selenium是一个Web的自动化测试工具,它可以根据我们的指令,让浏览器自动加载页面,获取需要的数据,甚至页面截屏,或者判断网站上某些动作是否发生.但是它自身不带浏览器,不支持浏览器的功能,因此它 ...
- Spring MVC参数处理
使用Servlet API作为参数 HttpServletRequest HttpServletResponse HttpSession 使用流作为参数 总结 Spring MVC通过分析处理处理方法 ...
- 客户端,Scala:Spark查询Phoenix
客户端,Scala:Spark查询Phoenix 1.pom.xml 2.配置文件 2.1config.properties 2.2MyConfig 3.entity实体(与phoenix中的tabl ...
- 码一次前后台post请求交互,以及接口的使用,json数据格式的传递
近几天,公司疯狂加班,然后补做了很多功能,很多东西虽然是自己熟悉的,但是却不会上手,动手实践能力仍需加强,对此对一些代码记录,留待学习和总结. 简单描述功能 具体实现 前台JSP.JS.后台actio ...
- redis学习教程四《管理、备份、客户端连接》
redis学习教程四<管理.备份.客户端连接> 一:Redis服务器命令 Redis服务器命令 下表列出了与Redis服务器相关的一些基本命令. 序号 命令 说明 1 BGREWRITE ...
- K8s client 使用
使用的k8s client包: <dependency> <groupId>io.fabric8</groupId> <artifactId>kuber ...
- php 7.4 vcruntime140.dll not compatible with PHP
安装PHP7.4以上版本时,在运行PHP时会提示如下: PHP Warning: 'vcruntime140.dll' 14.0 is not compatible with this PHP bui ...
- Luogu T14448 区间开方
题面版权来自Shlw.题目链接 题目背景 无 题目描述 给定一个数列,元素均为正整数,对其以下两种操作: 1.将某区间每一个数变为其算术平方根(取整) 2.求出某区间内所有数的最大值 输入输出格式 输 ...
- 2019牛客多校 Round5
Solved:4 Rank:122 补题:8/10 A digits 2 签到 把这个数写n遍 #include <bits/stdc++.h> using namespace std; ...