Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

fix(cache): skip cache for screenshots with custom viewport or quality settings (#2677)

firecrawl-spring[bot]c9b21011f8cb
diff --git a/apps/api/src/scraper/scrapeURL/engines/index.ts b/apps/api/src/scraper/scrapeURL/engines/index.ts
index 151e711db..e9197ec47 100644
--- a/apps/api/src/scraper/scrapeURL/engines/index.ts
+++ b/apps/api/src/scraper/scrapeURL/engines/index.ts
@@ -465,6 +465,12 @@ const engineOptions: {
};
export function shouldUseIndex(meta: Meta) {
+ // Skip index if screenshot format has custom viewport or quality settings
+ const screenshotFormat = hasFormatOfType(meta.options.formats, "screenshot");
+ const hasCustomScreenshotSettings =
+ screenshotFormat?.viewport !== undefined ||
+ screenshotFormat?.quality !== undefined;
+
return (
useIndex &&
config.FIRECRAWL_INDEX_WRITE_ONLY !== true &&
@@ -472,6 +478,7 @@ export function shouldUseIndex(meta: Meta) {
!hasFormatOfType(meta.options.formats, "branding") &&
// Skip index if a non-default PDF maxPages is specified
getPDFMaxPages(meta.options.parsers) === undefined &&
+ !hasCustomScreenshotSettings &&
meta.options.maxAge !== 0 &&
(meta.options.headers === undefined ||
Object.keys(meta.options.headers).length === 0) &&
diff --git a/apps/api/src/scraper/scrapeURL/engines/index/index.ts b/apps/api/src/scraper/scrapeURL/engines/index/index.ts
index 06425d702..908f75cf4 100644
--- a/apps/api/src/scraper/scrapeURL/engines/index/index.ts
+++ b/apps/api/src/scraper/scrapeURL/engines/index/index.ts
@@ -16,8 +16,15 @@ import {
} from "../../../../services";
import { EngineError, IndexMissError, NoCachedDataError } from "../../error";
import { shouldParsePDF } from "../../../../controllers/v2/types";
+import { hasFormatOfType } from "../../../../lib/format-utils";
export async function sendDocumentToIndex(meta: Meta, document: Document) {
+ // Skip caching if screenshot format has custom viewport or quality settings
+ const screenshotFormat = hasFormatOfType(meta.options.formats, "screenshot");
+ const hasCustomScreenshotSettings =
+ screenshotFormat?.viewport !== undefined ||
+ screenshotFormat?.quality !== undefined;
+
const shouldCache =
meta.options.storeInCache &&
!meta.internalOptions.zeroDataRetention &&
@@ -39,6 +46,7 @@ export async function sendDocumentToIndex(meta: Meta, document: Document) {
meta.winnerEngine !== "fire-engine;tlsclient;stealth" &&
meta.winnerEngine !== "fetch")) &&
!meta.featureFlags.has("actions") &&
+ !hasCustomScreenshotSettings &&
(meta.options.headers === undefined ||
Object.keys(meta.options.headers).length === 0);