{"record":{"id":"a64130f045432cd8","repo":"firecrawl/open-lovable","slug":"failed-to-capture-screenshot","errorCode":null,"errorMessage":"Failed to capture screenshot","messagePattern":"Failed to capture screenshot","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"app/api/scrape-screenshot/route.ts","lineNumber":64,"sourceCode":"    // Check if we have data with screenshot\n    if (scrapeResult && scrapeResult.screenshot) {\n      // Direct screenshot response\n      return NextResponse.json({\n        success: true,\n        screenshot: scrapeResult.screenshot,\n        metadata: scrapeResult.metadata || {}\n      });\n    } else if ((scrapeResult as any)?.data?.screenshot) {\n      // Nested data structure\n      return NextResponse.json({\n        success: true,\n        screenshot: (scrapeResult as any).data.screenshot,\n        metadata: (scrapeResult as any).data.metadata || {}\n      });\n    } else if ((scrapeResult as any)?.success === false) {\n      // Explicit failure\n      console.error('[scrape-screenshot] Firecrawl API error:', (scrapeResult as any).error);\n      throw new Error((scrapeResult as any).error || 'Failed to capture screenshot');\n    } else {\n      // No screenshot in response\n      console.error('[scrape-screenshot] No screenshot in response. Full response:', JSON.stringify(scrapeResult, null, 2));\n      throw new Error('Screenshot not available in response - check console for full response structure');\n    }\n\n  } catch (error: any) {\n    console.error('[scrape-screenshot] Screenshot capture error:', error);\n    console.error('[scrape-screenshot] Error stack:', error.stack);\n    \n    // Provide fallback response for development - removed NODE_ENV check as it doesn't work in Next.js production builds\n    \n    return NextResponse.json({ \n      error: error.message || 'Failed to capture screenshot'\n    }, { status: 500 });\n  }\n}","sourceCodeStart":46,"sourceCodeEnd":81,"githubUrl":"https://github.com/firecrawl/open-lovable/blob/69bd93bae7a9c97ef989eb70aabe6797fb3dac89/app/api/scrape-screenshot/route.ts#L46-L81","documentation":"The route's generic failure error for screenshot scraping: thrown when the Firecrawl scrape result reports `success === false` and its `error` field is empty, so no specific upstream reason is available. It indicates Firecrawl processed the request but could not produce a result.","triggerScenarios":"POST /api/scrape-screenshot where Firecrawl's response has `success: false` with a null/undefined `error` property — e.g. target page timed out, was blocked (403/captcha), or screenshot capture failed internally at Firecrawl.","commonSituations":"Scraping sites that block bots or require JS/login; screenshot format unsupported for the URL scheme (non-http URL); Firecrawl internal errors during rendering; transient network failures at scrape time.","solutions":["Retry the scrape once — many failures are transient rendering timeouts","Check the target URL is publicly reachable, http(s), and doesn't require login","Inspect Firecrawl dashboard/plan limits if failures persist (blocked domains, quota)","Log the full scrapeResult when success===false so the upstream error text isn't lost"],"exampleFix":"// before\n} else if ((scrapeResult as any)?.success === false) {\n  throw new Error((scrapeResult as any).error || 'Failed to capture screenshot');\n}\n// after\n} else if ((scrapeResult as any)?.success === false) {\n  console.error('[scrape-screenshot] full result:', JSON.stringify(scrapeResult));\n  throw new Error((scrapeResult as any).error || 'Failed to capture screenshot');\n}","handlingStrategy":"retry","validationCode":"const u = new URL(url);\nif (!/^https?:$/.test(u.protocol)) throw new Error('Only public http(s) pages can be screenshotted');","typeGuard":"function scrapeFailed(r: any): r is { success: false; error?: string } {\n  return r?.success === false;\n}","tryCatchPattern":"try {\n  return await captureScreenshot(url);\n} catch (e) {\n  if (e.message === 'Failed to capture screenshot') {\n    await sleep(1500);\n    return captureScreenshot(url); // transient render failures often succeed on retry\n  }\n  throw e;\n}","preventionTips":["Only pass publicly reachable, renderable http(s) URLs","Retry once with backoff for transient Firecrawl render failures","Log the full scrapeResult whenever success===false to preserve the upstream reason","Watch Firecrawl quota/dashboard for blocked domains or limits"],"tags":["firecrawl","screenshot","third-party-api"],"backgroundTag":"upstream-http-error","analyzedSha":"69bd93bae7a9c97ef989eb70aabe6797fb3dac89","analyzedAt":"2026-08-28T22:20:32.339Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}