Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ screenshot.clip.x | number | - | Specifies x-coordinate of top-left corner of cl
screenshot.clip.y | number | - | Specifies y-coordinate of top-left corner of clipping region of the page.
screenshot.clip.width | number | - | Specifies width of clipping region of the page.
screenshot.clip.height | number | - | Specifies height of clipping region of the page.
request.headers | object | - | (POST only) Override request headers.
request.method | string | - | Override request method.
request.postData | string | - | Override request postData.


**Example:**
Expand Down Expand Up @@ -250,6 +253,9 @@ The only required parameter is `url`.

// Passed to Puppeteer page.screenshot()
screenshot: { ... },

// Intercepts and overrides request
request: { ...},
}
```

Expand Down
8 changes: 8 additions & 0 deletions src/core/render-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ async function render(_opts = {}) {
}
});

if (opts.request) {
await page.setRequestInterception(true);
page.on('request', (request) => {
request.continue(opts.request);
});
}


let data;
try {
logger.info('Set browser viewport..');
Expand Down
5 changes: 5 additions & 0 deletions src/http/render-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ function getOptsFromQuery(query) {
},
omitBackground: query['screenshot.omitBackground'],
},
request: {
headers: query['request.headers'],
method: query['request.method'],
postData: query['request.postData'],
},
};
return opts;
}
Expand Down
8 changes: 8 additions & 0 deletions src/util/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ const sharedQuerySchema = Joi.object({
'screenshot.clip.width': Joi.number(),
'screenshot.clip.height': Joi.number(),
'screenshot.omitBackground': Joi.boolean(),
// 'request.headers': Joi.object(), // any way to send an object?
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if there are any clever workarounds here. Could optionally be a json string that gets decoded? I think #78 has this same issue.

'request.method': Joi.string().valid(['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'TRACE', 'PATCH']),
'request.postData': Joi.string(),
});

const renderQuerySchema = Joi.object({
Expand Down Expand Up @@ -126,6 +129,11 @@ const renderBodyObject = Joi.object({
omitBackground: Joi.boolean(),
}),
failEarly: Joi.string(),
request: Joi.object({
headers: Joi.object(),
method: Joi.string().valid(['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'TRACE', 'PATCH']),
postData: Joi.string(),
}),
});

const renderBodySchema = Joi.alternatives([
Expand Down