Skip to content

Open source alternative to Semrush and Ahrefs

Run the dashboard's site scan without rendering where no renderer exists (#1071)

Ben Senescu39a9fc3171b5
diff --git a/src/server/features/dashboard/services/DashboardCacheService.test.ts b/src/server/features/dashboard/services/DashboardCacheService.test.ts
index 8a20825a..4de0ed08 100644
--- a/src/server/features/dashboard/services/DashboardCacheService.test.ts
+++ b/src/server/features/dashboard/services/DashboardCacheService.test.ts
@@ -33,7 +33,9 @@ vi.mock("@/server/features/audit/repositories/AuditRepository", () => ({
AuditRepository: { getLatestAuditForProject: state.latestAudit },
}));
vi.mock("@/db", () => ({ db: state.db }));
-vi.mock("cloudflare:workers", () => ({ env: { DATABASE_PROVIDER: "d1" } }));
+vi.mock("cloudflare:workers", () => ({
+ env: { DATABASE_PROVIDER: "d1", AUDIT_BROWSER_RENDERING: "true" },
+}));
vi.mock("@/server/lib/r2-cache", async (importOriginal) => ({
...(await importOriginal<typeof R2Cache>()),
getCached: async (key: string) => state.cache.get(key) ?? null,
diff --git a/src/server/features/dashboard/services/DashboardFirstAuditService.ts b/src/server/features/dashboard/services/DashboardFirstAuditService.ts
index 3d7f222f..6bbf7094 100644
--- a/src/server/features/dashboard/services/DashboardFirstAuditService.ts
+++ b/src/server/features/dashboard/services/DashboardFirstAuditService.ts
@@ -1,6 +1,7 @@
import { waitUntil } from "cloudflare:workers";
import { shouldCaptureAppErrorCode } from "@/shared/error-codes";
import { AuditService } from "@/server/features/audit/services/AuditService";
+import { isAuditRenderingAllowed } from "@/server/lib/audit/rendering-policy";
import { AuditRepository } from "@/server/features/audit/repositories/AuditRepository";
import { DataRefreshClaimRepository } from "../repositories/DataRefreshClaimRepository";
import { buildCacheKey } from "@/server/lib/r2-cache";
@@ -44,7 +45,9 @@ async function start(
projectId,
startUrl: `https://${domain}`,
maxPages: 50,
- renderJavaScript: true,
+ // Installs with no renderer (Docker without a Context key) crawl
+ // without JavaScript instead of failing the first audit.
+ renderJavaScript: await isAuditRenderingAllowed(),
lighthouseStrategy: "none",
limitTier,
});
diff --git a/src/serverFunctions/audit.ts b/src/serverFunctions/audit.ts
index 3692f057..4ff62451 100644
--- a/src/serverFunctions/audit.ts
+++ b/src/serverFunctions/audit.ts
@@ -19,6 +19,11 @@ export const startAudit = createServerFn({ method: "POST" })
.validator(startAuditSchema)
.handler(async ({ data, context }) => {
const limitTier = await AuditService.resolveAuditLimitTier(context);
+ // The dashboard's scan button always asks for rendering; installs with no
+ // renderer (Docker without a Context key) crawl without it instead of
+ // failing. The launch form only offers rendering where it's available.
+ const renderJavaScript =
+ data.renderJavaScript && (await isAuditRenderingAllowed());
const result = await AuditService.startAudit({
actorUserId: context.userId,
@@ -28,7 +33,7 @@ export const startAudit = createServerFn({ method: "POST" })
maxPages: data.maxPages,
lighthouseStrategy: data.lighthouseStrategy,
limitTier,
- renderJavaScript: data.renderJavaScript,
+ renderJavaScript,
});
waitUntil(