fix: correct base64 encoding for Vision Analysis screenshots

- Previous chunked btoa approach encoded each chunk independently,
  producing corrupted base64 that Gemini couldn't parse (returned {})
- Now builds complete binary string first, then encodes once with btoa
- Added screenshot debug info to channel errors for diagnostics
- Confirmed: foundingYear 2004, doctors, gangnamunni data all extracted

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Haewon KamandClaude Opus 4.6 committed 2026-04-05 11:38:16 +09:00
1 parent 79950925a1
commit 82e9ec6cc0
2 files changed
+36 -11

No files matched your search

@@ -2,7 +2,7 @@ import "@supabase/functions-js/edge-runtime.d.ts";
import { createClient } from "https://esm.sh/@supabase/supabase-js@2";
import type { VerifiedChannels } from "../_shared/verifyHandles.ts";
import { PERPLEXITY_MODEL } from "../_shared/config.ts";
import { captureAllScreenshots, runVisionAnalysis, type ScreenshotResult } from "../_shared/visionAnalysis.ts";
import { captureAllScreenshots, runVisionAnalysis, screenshotErrors, type ScreenshotResult } from "../_shared/visionAnalysis.ts";
import { fetchWithRetry, fetchJsonWithRetry, wrapChannelTask, type ChannelTaskResult } from "../_shared/retry.ts";
const corsHeaders = {
@@ -395,17 +395,22 @@ Deno.serve(async (req) => {
channelData.visionPerPage = vision.perPage;
}
// Store screenshots (without base64 — just metadata for report)
// Store screenshots metadata (NOT base64 — use the GCS URL from Firecrawl)
channelData.screenshots = screenshots.map(ss => ({
id: ss.id,
url: ss.base64 ? `data:image/png;base64,${ss.base64}` : ss.url,
url: ss.url, // GCS signed URL (valid ~7 days)
channel: ss.channel,
capturedAt: ss.capturedAt,
caption: ss.caption,
sourceUrl: ss.sourceUrl,
}));
if (screenshots.length === 0) throw new Error("No screenshots captured");
if (screenshots.length === 0) {
const debugInfo = screenshotErrors.length > 0
? screenshotErrors.join(" | ")
: "No errors recorded — check FIRECRAWL_API_KEY";
throw new Error(`No screenshots captured: ${debugInfo}`);
}
}));
}