何を試しても、ヘッドレスChrome 60(および59)のフルページのスクリーンショットの最大高さは16,348ピクセルです。ヘッドレスChromeスクリーンショットの最大高さは16,384ピクセルですか?
メモリに問題はありません。 segfaultsはありません。たとえば、FATAL:memory_linux.cc(35) Out of memory.
というメッセージはありません。なし。スクリーンショットのキャプチャは「成功」です。スクリーンショット形式(PNGまたはJPEG)を変更しても効果はありません。
スクリーンショットの幅はさまざまですが、保存されたスクリーンショットの高さは常に16,348pxに制限されています。たとえば、
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)。どのようにこの高さを増やすことができますか?
このバグに記載されているようにこれはクロムの制限です/ issues/detail?id = 339725)。しかし、この投稿は2014年のものです。[この投稿](https://groups.google.com/a/chromium.org/forum/#!topic/headless-dev/qcvOjVUZ-WQ)も参考になるかもしれません。 – pattulus