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