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

Method handler

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

Source from the content-addressed store, hash-verified

80 path = [HTTPRoutes.chromiumContent, HTTPRoutes.content];
81 tags = [APITags.browserAPI];
82 async handler(
83 req: Request,
84 res: ServerResponse,
85 logger: Logger,
86 browser: BrowserInstance,
87 ): Promise<void> {
88 logger.debug(
89 'Content API invoked with body:',
90 redactSensitiveBodyFields(req.body),
91 );
92 const contentType =
93 !req.headers.accept || req.headers.accept?.includes('*')
94 ? contentTypes.html
95 : req.headers.accept;
96
97 if (!req.body) {
98 throw new BadRequest(`Couldn't parse JSON body`);
99 }
100
101 res.setHeader('Content-Type', contentType);
102
103 const {
104 bestAttempt = false,
105 url,
106 gotoOptions,
107 html,
108 authenticate,
109 addScriptTag = [],
110 addStyleTag = [],
111 cookies = [],
112 emulateMediaType,
113 rejectRequestPattern = [],
114 requestInterceptors = [],
115 rejectResourceTypes = [],
116 setExtraHTTPHeaders,
117 setJavaScriptEnabled,
118 userAgent,
119 viewport,
120 waitForTimeout,
121 waitForFunction,
122 waitForSelector,
123 waitForEvent,
124 } = req.body as BodySchema;
125
126 const content = url || html;
127
128 if (!content) {
129 throw new BadRequest(`One of "url" or "html" properties are required.`);
130 }
131
132 const config = browser.getConfig();
133 assertNavigationAllowed(
134 url,
135 config.getBlockedURLPatterns(),
136 config.getBlockedNetworkRanges(),
137 );
138
139 const page = (await browser.newPage()) as UnwrapPromise<

Callers

nothing calls this directly

Calls 14

assertNavigationAllowedFunction · 0.85
isBase64EncodedFunction · 0.85
bestAttemptCatchFunction · 0.85
toSetContentOptionsFunction · 0.85
writeResponseFunction · 0.85
debugMethod · 0.80
getBlockedURLPatternsMethod · 0.80
infoMethod · 0.80
sleepFunction · 0.50
getConfigMethod · 0.45

Tested by

no test coverage detected