Skip to content

Commit 4b15a12

Browse files
Implement support for html output for testing purposes
1 parent d8ea93c commit 4b15a12

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

src/core/render-core.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ async function render(_opts = {}) {
152152

153153
if (opts.output === 'pdf') {
154154
data = await page.pdf(opts.pdf);
155+
} else if (opts.output === 'html') {
156+
data = await page.evaluate(() => document.body.innerHTML);
155157
} else {
156158
// This is done because puppeteer throws an error if fullPage and clip is used at the same
157159
// time even though clip is just empty object {}

src/http/render-http.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ const renderCore = require('../core/render-core');
55
function getMimeType(opts) {
66
if (opts.output === 'pdf') {
77
return 'application/pdf';
8+
} else if (opts.output === 'html') {
9+
return 'text/html';
810
}
11+
912
const type = _.get(opts, 'screenshot.type');
1013
switch (type) {
1114
case 'png': return 'image/png';

src/util/validation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const sharedQuerySchema = Joi.object({
2929
Joi.string().min(1).max(2000),
3030
]),
3131
cookies: Joi.array().items(cookieSchema),
32-
output: Joi.string().valid(['pdf', 'screenshot']),
32+
output: Joi.string().valid(['pdf', 'screenshot', 'html']),
3333
'viewport.width': Joi.number().min(1).max(30000),
3434
'viewport.height': Joi.number().min(1).max(30000),
3535
'viewport.deviceScaleFactor': Joi.number().min(0).max(100),
@@ -76,7 +76,7 @@ const renderBodyObject = Joi.object({
7676
ignoreHttpsErrors: Joi.boolean(),
7777
emulateScreenMedia: Joi.boolean(),
7878
cookies: Joi.array().items(cookieSchema),
79-
output: Joi.string().valid(['pdf', 'screenshot']),
79+
output: Joi.string().valid(['pdf', 'screenshot', 'html']),
8080
viewport: Joi.object({
8181
width: Joi.number().min(1).max(30000),
8282
height: Joi.number().min(1).max(30000),

0 commit comments

Comments
 (0)