diff --git a/lib/Page.js b/lib/Page.js index 8adbafbc..e2aa3290 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -614,7 +614,12 @@ class Page extends EventEmitter { */ async screenshot(options = {}) { let screenshotType = null; - if (options.path) { + // options.type takes precedence over inferring the type from options.path + // because it may be a 0-length file with no extension created beforehand (i.e. as a temp file). + if (options.type) { + console.assert(options.type === 'png' || options.type === 'jpeg', 'Unknown options.type value: ' + options.type); + screenshotType = options.type; + } else if (options.path) { const mimeType = mime.lookup(options.path); if (mimeType === 'image/png') screenshotType = 'png'; @@ -622,11 +627,7 @@ class Page extends EventEmitter { screenshotType = 'jpeg'; console.assert(screenshotType, 'Unsupported screenshot mime type: ' + mimeType); } - if (options.type) { - console.assert(!screenshotType || options.type === screenshotType, `Passed screenshot type '${options.type}' does not match the type inferred from the file path: '${screenshotType}'`); - console.assert(options.type === 'png' || options.type === 'jpeg', 'Unknown options.type value: ' + options.type); - screenshotType = options.type; - } + if (!screenshotType) screenshotType = 'png';