Skip to content

Commit

Permalink
Implement support for html output for testing purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
kimmobrunfeldt committed Jan 28, 2020
1 parent d8ea93c commit 4b15a12
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/core/render-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down
3 changes: 3 additions & 0 deletions src/http/render-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
4 changes: 2 additions & 2 deletions src/util/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 4b15a12

Please sign in to comment.