(
req: Request,
res: ServerResponse,
logger: Logger,
browser: BrowserInstance,
)
| 86 | path = [HTTPRoutes.chromiumPdf, HTTPRoutes.pdf]; |
| 87 | tags = [APITags.browserAPI]; |
| 88 | async handler( |
| 89 | req: Request, |
| 90 | res: ServerResponse, |
| 91 | logger: Logger, |
| 92 | browser: BrowserInstance, |
| 93 | ): Promise<void> { |
| 94 | logger.debug( |
| 95 | 'PDF API invoked with body:', |
| 96 | redactSensitiveBodyFields(req.body), |
| 97 | ); |
| 98 | const contentType = |
| 99 | !req.headers.accept || req.headers.accept?.includes('*') |
| 100 | ? 'application/pdf' |
| 101 | : req.headers.accept; |
| 102 | |
| 103 | if (!req.body) { |
| 104 | throw new BadRequest(`Couldn't parse JSON body`); |
| 105 | } |
| 106 | |
| 107 | res.setHeader('Content-Type', contentType); |
| 108 | |
| 109 | const { |
| 110 | url, |
| 111 | gotoOptions, |
| 112 | authenticate, |
| 113 | html, |
| 114 | addScriptTag = [], |
| 115 | addStyleTag = [], |
| 116 | cookies = [], |
| 117 | emulateMediaType, |
| 118 | rejectRequestPattern = [], |
| 119 | requestInterceptors = [], |
| 120 | rejectResourceTypes = [], |
| 121 | options, |
| 122 | setExtraHTTPHeaders, |
| 123 | setJavaScriptEnabled, |
| 124 | userAgent, |
| 125 | viewport, |
| 126 | waitForEvent, |
| 127 | waitForFunction, |
| 128 | waitForSelector, |
| 129 | waitForTimeout, |
| 130 | bestAttempt = false, |
| 131 | } = req.body as BodySchema; |
| 132 | |
| 133 | const content = url || html; |
| 134 | |
| 135 | if (!content) { |
| 136 | throw new BadRequest(`One of "url" or "html" properties are required.`); |
| 137 | } |
| 138 | |
| 139 | if (options?.fullPage && (options?.height || options?.format)) { |
| 140 | throw new BadRequest( |
| 141 | `"fullPage" option cannot be used with "height" or "format" options.`, |
| 142 | ); |
| 143 | } |
| 144 | |
| 145 | const config = browser.getConfig(); |
no test coverage detected