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

Method handler

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 13

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

Tested by

no test coverage detected