MCPcopy
hub / github.com/browserless/browserless / handler

Method handler

src/shared/scrape.http.ts:240–501  ·  view source on GitHub ↗
(
    req: Request,
    res: ServerResponse,
    logger: Logger,
    browser: BrowserInstance,
  )

Source from the content-addressed store, hash-verified

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 );

Callers

nothing calls this directly

Calls 13

assertNavigationAllowedFunction · 0.85
isBase64EncodedFunction · 0.85
bestAttemptCatchFunction · 0.85
toSetContentOptionsFunction · 0.85
jsonResponseFunction · 0.85
debugMethod · 0.80
getBlockedURLPatternsMethod · 0.80
sleepFunction · 0.50
getConfigMethod · 0.45
newPageMethod · 0.45

Tested by

no test coverage detected