【发布时间】:2017-11-19 20:34:44
【问题描述】:
无论我如何尝试,使用无头 Chrome 60(和 59)的整页屏幕截图的最大高度为 16,348 像素。
这不是内存问题。没有段错误,也没有例如FATAL:memory_linux.cc(35) Out of memory. 消息。没有。捕获屏幕截图是“成功的”。更改屏幕截图格式(PNG 或 JPEG)没有任何影响。
屏幕截图的宽度可能会有所不同,但保存的屏幕截图的高度始终限制为 16,348 像素。例如,
1600x16384、1200x16384、2400x16384 等
我正在使用这个最少的代码 (full source) 进行放大截图:
const upscale = 2;
const viewportWidth = 1200;
const viewportHeight = 800;
....
// Set up viewport resolution, etc.
const deviceMetrics = {
width: viewportWidth,
height: viewportHeight,
deviceScaleFactor: 0,
mobile: false,
fitWindow: false,
scale: 1 // Relative to the upscale
};
await Emulation.setDeviceMetricsOverride(deviceMetrics);
await Emulation.setVisibleSize({width: viewportWidth, height: viewportHeight});
await Emulation.setPageScaleFactor({pageScaleFactor: upscale});
// Navigate to target page
await Page.navigate({url});
const {root: {nodeId: documentNodeId}} = await DOM.getDocument();
const {nodeId: bodyNodeId} = await DOM.querySelector({
selector: 'body',
nodeId: documentNodeId,
});
const {model: {height}} = await DOM.getBoxModel({nodeId: bodyNodeId});
// Upscale the dimensions for full page
await Emulation.setVisibleSize({width: Math.round(viewportWidth * upscale), height: Math.round(height * upscale)});
// This forceViewport call ensures that content outside the viewport is
// rendered, otherwise it shows up as grey. Possibly a bug?
await Emulation.forceViewport({x: 0, y: 0, scale: upscale});
const screenshot = await Page.captureScreenshot({format});
const buffer = new Buffer(screenshot.data, 'base64');
file.writeFile(outFile, buffer, 'base64', function (err) {
if (err) {
console.error('Exception while saving screenshot:', err);
} else {
console.log('Screenshot saved');
}
client.close();
});
我也找不到任何有用的Chrome switches。这是 Chrome 的硬编码限制吗? 16384 是一个可疑数字 (2^14 = 16,384)。这个高度怎么增加?
【问题讨论】:
-
据我所知,这是Skia library 的限制。但是,该帖子来自 2014 年。This post 也可能提供信息。
标签: node.js google-chrome centos screenshot