2017-06-17 45 views
3

無論我嘗試什麼,無頭Chrome 60(和59)的全屏截圖的最大高度爲16,348px。無頭Chrome瀏覽器屏幕截圖的最大高度爲16,384px?

這不是內存問題。沒有段錯誤,也沒有,例如,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)。這個高度如何增加?

+0

從我讀它的[Skia的庫]的限制(https://bugs.chromium.org/p/chromium /問題/細節?ID = 339725)。但是,該帖子是從2014年開始的。[此帖子](https://groups.google.com/a/chromium.org/forum/#!topic/headless-dev/qcvOjVUZ-WQ)也可能提供信息。 – pattulus

回答

相關問題