diff --git a/src/core/render-core.js b/src/core/render-core.js index 1b1da83e..52bc9226 100644 --- a/src/core/render-core.js +++ b/src/core/render-core.js @@ -152,6 +152,8 @@ async function render(_opts = {}) { if (opts.output === 'pdf') { data = await page.pdf(opts.pdf); + } else if (opts.output === 'html') { + data = await page.evaluate(() => document.body.innerHTML); } else { // This is done because puppeteer throws an error if fullPage and clip is used at the same // time even though clip is just empty object {} diff --git a/src/http/render-http.js b/src/http/render-http.js index 2a5c2c2d..6c4a06d1 100644 --- a/src/http/render-http.js +++ b/src/http/render-http.js @@ -5,7 +5,10 @@ const renderCore = require('../core/render-core'); function getMimeType(opts) { if (opts.output === 'pdf') { return 'application/pdf'; + } else if (opts.output === 'html') { + return 'text/html'; } + const type = _.get(opts, 'screenshot.type'); switch (type) { case 'png': return 'image/png'; diff --git a/src/util/validation.js b/src/util/validation.js index 3c42074e..6a1adadf 100644 --- a/src/util/validation.js +++ b/src/util/validation.js @@ -29,7 +29,7 @@ const sharedQuerySchema = Joi.object({ Joi.string().min(1).max(2000), ]), cookies: Joi.array().items(cookieSchema), - output: Joi.string().valid(['pdf', 'screenshot']), + output: Joi.string().valid(['pdf', 'screenshot', 'html']), 'viewport.width': Joi.number().min(1).max(30000), 'viewport.height': Joi.number().min(1).max(30000), 'viewport.deviceScaleFactor': Joi.number().min(0).max(100), @@ -76,7 +76,7 @@ const renderBodyObject = Joi.object({ ignoreHttpsErrors: Joi.boolean(), emulateScreenMedia: Joi.boolean(), cookies: Joi.array().items(cookieSchema), - output: Joi.string().valid(['pdf', 'screenshot']), + output: Joi.string().valid(['pdf', 'screenshot', 'html']), viewport: Joi.object({ width: Joi.number().min(1).max(30000), height: Joi.number().min(1).max(30000),