MCPcopy
hub / github.com/firecrawl/firecrawl / browserCreateController

Function browserCreateController

apps/api/src/controllers/v2/browser.ts:193–392  ·  view source on GitHub ↗
(
  req: RequestWithAuth<{}, BrowserCreateResponse, BrowserCreateRequest>,
  res: Response<BrowserCreateResponse>,
)

Source from the content-addressed store, hash-verified

191// ---------------------------------------------------------------------------
192
193export async function browserCreateController(
194 req: RequestWithAuth<{}, BrowserCreateResponse, BrowserCreateRequest>,
195 res: Response<BrowserCreateResponse>,
196) {
197 // if (!req.acuc?.flags?.browserBeta) {
198 // return res.status(403).json({
199 // success: false,
200 // error:
201 // "Browser is currently in beta. Please contact support@firecrawl.com to request access.",
202 // });
203 // }
204
205 const sessionId = uuidv7();
206 const logger = _logger.child({
207 sessionId,
208 teamId: req.auth.team_id,
209 module: "api/v2",
210 method: "browserCreateController",
211 });
212
213 req.body = browserCreateRequestSchema.parse(req.body);
214
215 const { ttl, activityTtl, streamWebView, profile, integration } = req.body;
216
217 if (!config.BROWSER_SERVICE_URL) {
218 return res.status(503).json({
219 success: false,
220 error:
221 "Browser feature is not configured (BROWSER_SERVICE_URL is missing).",
222 });
223 }
224
225 logger.info("Creating browser session", { ttl, activityTtl });
226
227 // 0a. Check if team has enough credits for the full TTL
228 const estimatedCredits = calculateBrowserSessionCredits(ttl * 1000);
229 const autumnResult = await autumnService.checkCredits({
230 teamId: req.auth.team_id,
231 value: estimatedCredits,
232 properties: { source: "browserCreate", path: req.path },
233 });
234
235 if (autumnResult !== null && !autumnResult.allowed) {
236 logger.warn("Insufficient credits for browser session TTL", {
237 estimatedCredits,
238 ttl,
239 });
240 return res.status(402).json({
241 success: false,
242 error: `Insufficient credits for a ${ttl}s browser session (requires ~${estimatedCredits} credits). For more credits, you can upgrade your plan at https://firecrawl.dev/pricing.`,
243 });
244 }
245
246 // 0b. Enforce concurrency limit (shared pool with scrape/crawl/interact)
247 const concurrencyLimit = req.acuc?.concurrency ?? 2;
248 const activeCount = await getCombinedTeamActiveCount(req.auth.team_id);
249 if (activeCount >= concurrencyLimit) {
250 logger.warn("Concurrency limit reached for browser session", {

Callers

nothing calls this directly

Calls 11

logRequestFunction · 0.90
insertBrowserSessionFunction · 0.90
childMethod · 0.80
checkCreditsMethod · 0.80
browserServiceRequestFunction · 0.70
parseMethod · 0.45
jsonMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…