MCPcopy
hub / github.com/browserless/browserless / ScreenshotPost

Class ScreenshotPost

src/shared/screenshot.http.ts:75–306  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73}
74
75export default class ScreenshotPost extends BrowserHTTPRoute {
76 name = BrowserlessRoutes.ChromiumScreenshotPostRoute;
77 accepts = [contentTypes.json];
78 auth = true;
79 browser = ChromiumCDP;
80 concurrency = true;
81 contentTypes = [contentTypes.png, contentTypes.jpeg, contentTypes.text];
82 description = dedent(`
83 A JSON-based API for getting a screenshot binary from either a supplied
84 "url" or "html" payload in your request. Many options exist including
85 cookies, user-agents, setting timers and network mocks.
86 `);
87 method = Methods.post;
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,

Callers

nothing calls this directly

Calls 1

dedentFunction · 0.85

Tested by

no test coverage detected