Dra*_*kes 6 screenshot google-chrome centos node.js
无论我尝试什么,使用无头 Chrome 60(和 59)的全页屏幕截图的最大高度为 16,348 像素。
这不是内存问题。没有段错误,也没有,例如,FATAL:memory_linux.cc(35) Out of memory.消息。没有任何。捕获屏幕截图是“成功的”。更改屏幕截图格式 - PNG 或 JPEG - 没有影响。
屏幕截图的宽度可能会有所不同,但保存的屏幕截图的高度始终限制在 16,348 像素。例子,
1600x16384、1200x16384、2400x16384等
我正在使用这个最少的代码(完整源代码)进行放大截图:
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();
});
Run Code Online (Sandbox Code Playgroud)
我也找不到任何有用的Chrome 开关。这是 Chrome 的硬编码限制吗?16384 是一个可疑数字 (2^14 = 16,384)。这个高度如何增加?
| 归档时间: |
|
| 查看次数: |
1387 次 |
| 最近记录: |