(
req: Request,
res: ServerResponse,
logger: Logger,
browser: BrowserInstance,
)
| 238 | path = [HTTPRoutes.chromiumScrape, HTTPRoutes.scrape]; |
| 239 | tags = [APITags.browserAPI]; |
| 240 | async handler( |
| 241 | req: Request, |
| 242 | res: ServerResponse, |
| 243 | logger: Logger, |
| 244 | browser: BrowserInstance, |
| 245 | ) { |
| 246 | logger.debug( |
| 247 | 'Scrape API invoked with body:', |
| 248 | redactSensitiveBodyFields(req.body), |
| 249 | ); |
| 250 | const contentType = |
| 251 | !req.headers.accept || req.headers.accept?.includes('*') |
| 252 | ? contentTypes.html |
| 253 | : req.headers.accept; |
| 254 | |
| 255 | if (!req.body) { |
| 256 | throw new BadRequest(`Couldn't parse JSON body`); |
| 257 | } |
| 258 | |
| 259 | res.setHeader('Content-Type', contentType); |
| 260 | |
| 261 | const { |
| 262 | bestAttempt = false, |
| 263 | url, |
| 264 | gotoOptions, |
| 265 | authenticate, |
| 266 | addScriptTag = [], |
| 267 | addStyleTag = [], |
| 268 | cookies = [], |
| 269 | debugOpts, |
| 270 | elements, |
| 271 | emulateMediaType, |
| 272 | html, |
| 273 | rejectRequestPattern = [], |
| 274 | requestInterceptors = [], |
| 275 | rejectResourceTypes = [], |
| 276 | setExtraHTTPHeaders, |
| 277 | setJavaScriptEnabled, |
| 278 | userAgent, |
| 279 | viewport, |
| 280 | waitForTimeout, |
| 281 | waitForFunction, |
| 282 | waitForSelector, |
| 283 | waitForEvent, |
| 284 | } = req.body as BodySchema; |
| 285 | |
| 286 | const content = url || html; |
| 287 | |
| 288 | if (!content) { |
| 289 | throw new BadRequest(`One of "url" or "html" properties are required.`); |
| 290 | } |
| 291 | |
| 292 | const config = browser.getConfig(); |
| 293 | assertNavigationAllowed( |
| 294 | url, |
| 295 | config.getBlockedURLPatterns(), |
| 296 | config.getBlockedNetworkRanges(), |
| 297 | ); |
nothing calls this directly
no test coverage detected