Skip to content

Automate browser based workflows with AI

feat(SKY-9498): chunk-load recovery + Sheets funnel telemetry (#5817)

Aaron Perezf43625f7ea04
diff --git a/skyvern-frontend/src/App.tsx b/skyvern-frontend/src/App.tsx
index f193f16b6..aa6c0e056 100644
--- a/skyvern-frontend/src/App.tsx
+++ b/skyvern-frontend/src/App.tsx
@@ -7,9 +7,11 @@ import { queryClient } from "./api/QueryClient";
import { PostHogProvider } from "posthog-js/react";
import { LoggingContext, loggingStub } from "@/store/LoggingContext";
import { UserContext } from "@/store/UserContext";
+import { dropNoiseExceptions } from "@/util/posthogNoiseFilter";
const postHogOptions = {
api_host: "https://app.posthog.com",
+ before_send: dropNoiseExceptions,
};
const getLogging = () => {
diff --git a/skyvern-frontend/src/hooks/useCurrentOrgId.ts b/skyvern-frontend/src/hooks/useCurrentOrgId.ts
new file mode 100644
index 000000000..dd085614c
--- /dev/null
+++ b/skyvern-frontend/src/hooks/useCurrentOrgId.ts
@@ -0,0 +1,16 @@
+import { useQueryClient } from "@tanstack/react-query";
+import { OrganizationApiResponse } from "@/api/types";
+
+// Cache-only read of the current org id. The cloud shell (RootLayout +
+// useApiCredential) populates ["organizations"] on entry; this hook returns
+// undefined when the cache is empty, which keeps the OSS bundle from firing
+// any extra GET /organizations/ requests at render time. Returns the first
+// (primary) org — same convention used by RootLayout, useApiCredential, and
+// CloudSettings; multi-org users still emit a stable per-account org_id.
+export function useCurrentOrgId(): string | undefined {
+ const queryClient = useQueryClient();
+ const data = queryClient.getQueryData<Array<OrganizationApiResponse>>([
+ "organizations",
+ ]);
+ return data?.[0]?.organization_id;
+}
diff --git a/skyvern-frontend/src/main.tsx b/skyvern-frontend/src/main.tsx
index f25366e5e..1a0ad689a 100644
--- a/skyvern-frontend/src/main.tsx
+++ b/skyvern-frontend/src/main.tsx
@@ -2,6 +2,9 @@ import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App.tsx";
import "./index.css";
+import { installChunkLoadErrorHandler } from "./util/lazyWithReload";
+
+installChunkLoadErrorHandler();
ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
diff --git a/skyvern-frontend/src/routes/workflows/components/SheetTabCombobox.tsx b/skyvern-frontend/src/routes/workflows/components/SheetTabCombobox.tsx
index 25a66441c..0644a4b2a 100644
--- a/skyvern-frontend/src/routes/workflows/components/SheetTabCombobox.tsx
+++ b/skyvern-frontend/src/routes/workflows/components/SheetTabCombobox.tsx
@@ -1,7 +1,9 @@
import { ExternalLinkIcon } from "@radix-ui/react-icons";
-import { useMemo, useRef, useState } from "react";
+import { useEffect, useMemo, useRef, useState } from "react";
+import { usePostHog } from "posthog-js/react";
import { useGoogleSheetTabs } from "@/hooks/useGoogleSheetTabs";
import { useCreateGoogleSheetTab } from "@/hooks/useCreateGoogleSheetTab";
+import { useCurrentOrgId } from "@/hooks/useCurrentOrgId";
import {
Popover,
PopoverAnchor,
@@ -14,6 +16,10 @@ import {
isTemplateExpression,
} from "@/util/googleSheetsUrl";
import { isReconnectRequired } from "@/util/googleSheetsErrors";
+import {
+ describeAxiosError,
+ type SheetsBlockType,
+} from "@/util/sheetsTelemetry";
import { InlineCreateRow } from "./InlineCreateRow";
type Props = {
@@ -24,6 +30,7 @@ type Props = {
value: string;
placeholder?: string;
allowCreate: boolean;
+ blockType: SheetsBlockType;
onChange: (value: string) => void;
onSelect: (tabName: string) => void;
};
@@ -36,11 +43,14 @@ function SheetTabCombobox({
value,
placeholder,
allowCreate,
+ blockType,
onChange,
onSelect,
}: Props) {
const [isOpen, setIsOpen] = useState(false);
const anchorRef = useRef<HTMLDivElement>(null);
+ const postHog = usePostHog();
+ const orgId = useCurrentOrgId();
const isTypeable =
hasSelectedAccount &&
@@ -91,7 +101,13 @@ function SheetTabCombobox({
spreadsheetUrl={spreadsheetUrl}
filter={value}
allowCreate={allowCreate}
- onPick={(name) => {
+ blockType={blockType}
+ onPick={(name, tabIndex) => {
+ postHog?.capture("sheets.tab.selected", {
+ org_id: orgId,
+ block_type: blockType,
+ tab_index: tabIndex,
+ });
onSelect(name);
setIsOpen(false);
}}
@@ -106,7 +122,8 @@ type ListPanelProps = {
spreadsheetUrl: string;
filter: string;
allowCreate: boolean;
- onPick: (tabName: string) => void;
+ blockType: SheetsBlockType;
+ onPick: (tabName: string, tabIndex: number) => void;
};
function SheetTabListPanel({
@@ -114,8 +131,13 @@ function SheetTabListPanel({
spreadsheetUrl,
filter,
allowCreate,
+ blockType,
onPick,
}: ListPanelProps) {
+ const postHog = usePostHog();
+ const orgId = useCurrentOrgId();
+ const errorReportedRef = useRef<unknown>(null);
+ const loadedReportedRef = useRef(false);
const tabsQuery = useGoogleSheetTabs({
credentialId,
spreadsheetUrlOrId: spreadsheetUrl,
@@ -123,6 +145,44 @@ function SheetTabListPanel({
});
const createMutation = useCreateGoogleSheetTab();
+ // Reset dedup refs when the underlying spreadsheet/credential changes so
+ // telemetry reflects the new selection rather than a single per-mount fire.
+ useEffect(() => {
+ errorReportedRef.current = null;
+ loadedReportedRef.current = false;
+ }, [credentialId, spreadsheetUrl]);
+
+ useEffect(() => {
+ if (!tabsQuery.error) {
+ errorReportedRef.current = null;
+ } else if (errorReportedRef.current !== tabsQuery.error) {
+ errorReportedRef.current = tabsQuery.error;
+ const meta = describeAxiosError(tabsQuery.error);
+ postHog?.capture("sheets.tab.error", {
+ org_id: orgId,
+ block_type: blockType,
+ error_code: meta.error_code,
+ http_status: meta.http_status,
+ });
+ return;
+ }
+ if (!tabsQuery.isFetching && tabsQuery.data && !loadedReportedRef.current) {
+ loadedReportedRef.current = true;
+ postHog?.capture("sheets.tab.loaded", {
+ org_id: orgId,
+ block_type: blockType,
+ tab_count: tabsQuery.data.length,
+ });
+ }
+ }, [
+ tabsQuery.error,
+ tabsQuery.data,
+ tabsQuery.isFetching,
+ postHog,
+ orgId,
+ blockType,
+ ]);
+
const tabs = useMemo(() => {
const list = tabsQuery.data ?? [];
const needle = filter.trim().toLowerCase();
@@ -158,7 +218,7 @@ function SheetTabListPanel({
spreadsheetUrlOrId: spreadsheetUrl,
title,
});
- onPick(tab.title);
+ onPick(tab.title, -1);
};
return (
@@ -183,11 +243,11 @@ function SheetTabListPanel({
) : tabs.length === 0 ? (
<div className="px-3 py-3 text-xs text-slate-500">No sheets.</div>
) : (
- tabs.map((tab) => (
+ tabs.map((tab, index) => (
<button
key={tab.sheet_id}
type="button"
- onClick={() => onPick(tab.title)}
+ onClick={() => onPick(tab.title, index)}
className="flex w-full px-3 py-2 text-left text-xs text-slate-200 hover:bg-slate-700"
>
{tab.title}
diff --git a/skyvern-frontend/src/routes/workflows/components/SpreadsheetCombobox.tsx b/skyvern-frontend/src/routes/workflows/components/SpreadsheetCombobox.tsx
index 322cedecc..536ef94ee 100644
--- a/skyvern-frontend/src/routes/workflows/components/SpreadsheetCombobox.tsx
+++ b/skyvern-frontend/src/routes/workflows/components/SpreadsheetCombobox.tsx
@@ -1,8 +1,10 @@
import { ExternalLinkIcon, ReloadIcon } from "@radix-ui/react-icons";
import { useEffect, useMemo, useRef, useState } from "react";
+import { usePostHog } from "posthog-js/react";
import { useDebounce } from "use-debounce";
import { useGoogleSpreadsheets } from "@/hooks/useGoogleSpreadsheets";
import { useCreateGoogleSpreadsheet } from "@/hooks/useCreateGoogleSpreadsheet";
+import { useCurrentOrgId } from "@/hooks/useCurrentOrgId";
import {
Popover,
PopoverAnchor,
@@ -17,6 +19,11 @@ import {
isTemplateExpression,
} from "@/util/googleSheetsUrl";
import { isReconnectRequired } from "@/util/googleSheetsErrors";
+import {
+ describeAxiosError,
+ hashSpreadsheetId,
+ type SheetsBlockType,
+} from "@/util/sheetsTelemetry";
import { InlineCreateRow } from "./InlineCreateRow";
type Selection = {
@@ -33,6 +40,7 @@ type Props = {
displayName: string | null;
placeholder?: string;
allowCreate: boolean;
+ blockType: SheetsBlockType;
onChange: (value: string) => void;
onSelect: (selection: Selection) => void;
};
@@ -45,11 +53,14 @@ function SpreadsheetCombobox({
displayName,
placeholder,
allowCreate,
+ blockType,
onChange,
onSelect,
}: Props) {
const [isOpen, setIsOpen] = useState(false);
const anchorRef = useRef<HTMLDivElement>(null);
+ const postHog = usePostHog();
+ const orgId = useCurrentOrgId();
const renderedValue = displayName ?? value;
// Skip the Drive search whenever we already have a resolved selection
// (displayName) or the input is a parseable URL/ID. Drive `q` searches by
@@ -76,6 +87,32 @@ function SpreadsheetCombobox({
}
};
+ const popoverOpen = isOpen && isTypeable;
+ useEffect(() => {
+ if (popoverOpen) {
+ postHog?.capture("sheets.spreadsheet.picker.opened", {
+ org_id: orgId,
+ block_type: blockType,
+ });
+ }
+ }, [popoverOpen, postHog, orgId, blockType]);
+
+ const handlePick = (selection: Selection) => {
+ onSelect(selection);
+ setIsOpen(false);
+ // Hash off the hot path so a slow SubtleCrypto call never blocks the UI.
+ const spreadsheetId = extractSpreadsheetIdFromUrl(selection.url);
+ void (
+ spreadsheetId ? hashSpreadsheetId(spreadsheetId) : Promise.resolve(null)
+ ).then((spreadsheetIdHash) => {
+ postHog?.capture("sheets.spreadsheet.picker.selected", {
+ org_id: orgId,
+ block_type: blockType,
+ spreadsheet_id_hash: spreadsheetIdHash,
+ });
+ });
+ };
+
return (
<Popover open={isOpen && isTypeable} onOpenChange={setIsOpen}>
<PopoverAnchor asChild>
@@ -106,10 +143,8 @@ function SpreadsheetCombobox({
credentialId={credentialId}
query={debouncedQuery}
allowCreate={allowCreate}
- onPick={(selection) => {
- onSelect(selection);
- setIsOpen(false);
- }}
+ blockType={blockType}
+ onPick={handlePick}
/>
</PopoverContent>
</Popover>
@@ -120,6 +155,7 @@ type ListPanelProps = {
credentialId: string;
query: string;
allowCreate: boolean;
+ blockType: SheetsBlockType;
onPick: (selection: Selection) => void;
};
@@ -127,9 +163,13 @@ function SpreadsheetListPanel({
credentialId,
query,
allowCreate,
+ blockType,
onPick,
}: ListPanelProps) {
const scrollRef = useRef<HTMLDivElement>(null);
+ const postHog = usePostHog();
+ const orgId = useCurrentOrgId();
+ const errorReportedRef = useRef<unknown>(null);
const listing = useGoogleSpreadsheets({
credentialId,
query,
@@ -142,6 +182,27 @@ function SpreadsheetListPanel({
[listing.data],
);
+ // Reset dedup so a new credential gets a fresh error window.
+ useEffect(() => {
+ errorReportedRef.current = null;
+ }, [credentialId]);
+
+ useEffect(() => {
+ if (!listing.error) {
+ errorReportedRef.current = null;
+ return;
+ }
+ if (errorReportedRef.current === listing.error) return;
+ errorReportedRef.current = listing.error;
+ const meta = describeAxiosError(listing.error);
+ postHog?.capture("sheets.spreadsheet.picker.error", {
+ org_id: orgId,
+ block_type: blockType,
+ error_code: meta.error_code,
+ http_status: meta.http_status,
+ });
+ }, [listing.error, postHog, orgId, blockType]);
+
useEffect(() => {
const el = scrollRef.current;
if (!el) return;
diff --git a/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsx b/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsx
index 389328338..dab6bdcdd 100644
--- a/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsx
+++ b/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsx
@@ -72,6 +72,7 @@ import {
nodeTypes,
WorkflowBlockNode,
} from "./nodes";
+import { blockTypeFromNode } from "./nodes/blockTypeFromNode";
import {
ParametersState,
parameterIsSkyvernCredential,
@@ -663,7 +664,7 @@ function FlowRenderer({
workflowChangesStore.setHasChanges(true);
postHog.capture("builder.block.removed", {
org_id: workflow.organization_id,
- block_type: node.type,
+ block_type: blockTypeFromNode(node) ?? node.type,
});
doLayout(newNodesWithUpdatedParameters, newEdges);
diff --git a/skyvern-frontend/src/routes/workflows/editor/Workspace.tsx b/skyvern-frontend/src/routes/workflows/editor/Workspace.tsx
index 0b27d8004..52c35cfd7 100644
--- a/skyvern-frontend/src/routes/workflows/editor/Workspace.tsx
+++ b/skyvern-frontend/src/routes/workflows/editor/Workspace.tsx
@@ -91,6 +91,7 @@ import { cn } from "@/util/utils";
import { FlowRenderer, type FlowRendererProps } from "./FlowRenderer";
import { useWorkflowHistory } from "./hooks/useWorkflowHistory";
import { AppNode, isWorkflowBlockNode, WorkflowBlockNode } from "./nodes";
+import { blockTypeFromNode } from "./nodes/blockTypeFromNode";
import { ConditionalNodeData } from "./nodes/ConditionalNode/types";
import { WorkflowNodeLibraryPanel } from "./panels/WorkflowNodeLibraryPanel";
import { WorkflowParametersPanel } from "./panels/WorkflowParametersPanel";
@@ -1134,7 +1135,7 @@ function Workspace({
workflowChangesStore.setHasChanges(true);
postHog.capture("builder.block.added", {
org_id: workflow.organization_id,
- block_type: nodeType,
+ block_type: blockTypeFromNode(node) ?? nodeType,
position: previousNodeIndex + 1,
});
doLayout(newNodesAfter, [...editedEdges, ...newEdges]);
diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/GoogleSheetsReadNode/GoogleSheetsReadNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/GoogleSheetsReadNode/GoogleSheetsReadNode.tsx
index 86fe16a0b..b12f96404 100644
--- a/skyvern-frontend/src/routes/workflows/editor/nodes/GoogleSheetsReadNode/GoogleSheetsReadNode.tsx
+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/GoogleSheetsReadNode/GoogleSheetsReadNode.tsx
@@ -171,6 +171,7 @@ function GoogleSheetsReadNode({
displayName={effectiveDisplayName}
placeholder="Search or paste a spreadsheet URL"
allowCreate={false}
+ blockType="google_sheets_read"
onChange={(value) => {
setSpreadsheetDisplayName(null);
const oldId = extractSpreadsheetIdFromUrl(
@@ -230,6 +231,7 @@ function GoogleSheetsReadNode({
value={data.sheetName}
placeholder="Sheet1"
allowCreate={false}
+ blockType="google_sheets_read"
onChange={(value) => update({ sheetName: value })}
onSelect={(tabName) => update({ sheetName: tabName })}
/>
diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/GoogleSheetsWriteNode/GoogleSheetsWriteNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/GoogleSheetsWriteNode/GoogleSheetsWriteNode.tsx
index 03fc6b9d9..6d193816e 100644
--- a/skyvern-frontend/src/routes/workflows/editor/nodes/GoogleSheetsWriteNode/GoogleSheetsWriteNode.tsx
+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/GoogleSheetsWriteNode/GoogleSheetsWriteNode.tsx
@@ -223,6 +223,7 @@ function GoogleSheetsWriteNode({
displayName={effectiveDisplayName}
placeholder="Search or paste a spreadsheet URL"
allowCreate={true}
+ blockType="google_sheets_write"
onChange={(value) => {
setSpreadsheetDisplayName(null);
const oldId = extractSpreadsheetIdFromUrl(
@@ -348,6 +349,7 @@ function GoogleSheetsWriteNode({
value={data.sheetName}
placeholder="Sheet1"
allowCreate={true}
+ blockType="google_sheets_write"
onChange={(value) => update({ sheetName: value })}
onSelect={(tabName) => update({ sheetName: tabName })}
/>
diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/blockTypeFromNode.test.ts b/skyvern-frontend/src/routes/workflows/editor/nodes/blockTypeFromNode.test.ts
new file mode 100644
index 000000000..a22f19c6e
--- /dev/null
+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/blockTypeFromNode.test.ts
@@ -0,0 +1,48 @@
+import { describe, expect, it } from "vitest";
+import { blockTypeFromNode } from "./blockTypeFromNode";
+
+describe("blockTypeFromNode", () => {
+ it("returns null when type is missing", () => {
+ expect(blockTypeFromNode({})).toBeNull();
+ });
+
+ it("maps googleSheetsRead to google_sheets_read", () => {
+ expect(blockTypeFromNode({ type: "googleSheetsRead" })).toBe(
+ "google_sheets_read",
+ );
+ });
+
+ it("maps googleSheetsWrite to google_sheets_write", () => {
+ expect(blockTypeFromNode({ type: "googleSheetsWrite" })).toBe(
+ "google_sheets_write",
+ );
+ });
+
+ it("maps url to goto_url", () => {
+ expect(blockTypeFromNode({ type: "url" })).toBe("goto_url");
+ });
+
+ it("maps codeBlock to code", () => {
+ expect(blockTypeFromNode({ type: "codeBlock" })).toBe("code");
+ });
+
+ it("maps loop to for_loop by default", () => {
+ expect(blockTypeFromNode({ type: "loop", data: {} })).toBe("for_loop");
+ });
+
+ it("maps loop with loopKind=while to while_loop", () => {
+ expect(
+ blockTypeFromNode({ type: "loop", data: { loopKind: "while" } }),
+ ).toBe("while_loop");
+ });
+
+ it("maps loop with loopKind=for_each to for_loop", () => {
+ expect(
+ blockTypeFromNode({ type: "loop", data: { loopKind: "for_each" } }),
+ ).toBe("for_loop");
+ });
+
+ it("returns null for unknown values to surface missing mappings", () => {
+ expect(blockTypeFromNode({ type: "newBlockType" })).toBeNull();
+ });
+});
diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/blockTypeFromNode.ts b/skyvern-frontend/src/routes/workflows/editor/nodes/blockTypeFromNode.ts
new file mode 100644
index 000000000..d86ef3c7a
--- /dev/null
+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/blockTypeFromNode.ts
@@ -0,0 +1,45 @@
+import type { LoopNodeData } from "./LoopNode/types";
+
+// `loop` is intentionally absent — it is disambiguated to for_loop / while_loop
+// below based on the node's loopKind data field.
+const REACT_FLOW_TYPE_TO_BLOCK_TYPE: Record<string, string> = {
+ task: "task",
+ conditional: "conditional",
+ textPrompt: "text_prompt",
+ sendEmail: "send_email",
+ codeBlock: "code",
+ fileParser: "file_url_parser",
+ upload: "upload_to_s3",
+ fileUpload: "file_upload",
+ download: "download_to_s3",
+ validation: "validation",
+ human_interaction: "human_interaction",
+ action: "action",
+ navigation: "navigation",
+ extraction: "extraction",
+ login: "login",
+ wait: "wait",
+ fileDownload: "file_download",
+ pdfParser: "pdf_parser",
+ taskv2: "task_v2",
+ url: "goto_url",
+ http_request: "http_request",
+ printPage: "print_page",
+ workflowTrigger: "workflow_trigger",
+ googleSheetsRead: "google_sheets_read",
+ googleSheetsWrite: "google_sheets_write",
+};
+
+type Loopish = { type?: string; data?: Partial<LoopNodeData> };
+
+// Returns null when the React Flow type has no mapping so callers can decide a
+// safe fallback. Returning the raw camelCase type would silently break
+// snake_case-only PostHog funnels when a new node type is added.
+export function blockTypeFromNode(node: Loopish): string | null {
+ const reactFlowType = node?.type;
+ if (!reactFlowType) return null;
+ if (reactFlowType === "loop") {
+ return node.data?.loopKind === "while" ? "while_loop" : "for_loop";
+ }
+ return REACT_FLOW_TYPE_TO_BLOCK_TYPE[reactFlowType] ?? null;
+}
diff --git a/skyvern-frontend/src/util/geoSearch.ts b/skyvern-frontend/src/util/geoSearch.ts
index ff3c648e4..6e30c8984 100644
--- a/skyvern-frontend/src/util/geoSearch.ts
+++ b/skyvern-frontend/src/util/geoSearch.ts
@@ -5,6 +5,7 @@ import {
SUPPORTED_COUNTRY_CODES,
SupportedCountryCode,
} from "./geoData";
+import { importWithRetry } from "./lazyWithReload";
export type SearchResultItem = {
type: "country" | "subdivision" | "city";
@@ -30,7 +31,9 @@ let cscModulePromise: Promise<typeof import("country-state-city")> | null =
function loadCsc() {
if (!cscModulePromise) {
- cscModulePromise = import("country-state-city").catch((error) => {
+ cscModulePromise = importWithRetry(
+ () => import("country-state-city"),
+ ).catch((error) => {
// Reset on failure so next user action can retry
cscModulePromise = null;
throw error;
diff --git a/skyvern-frontend/src/util/lazyWithReload.ts b/skyvern-frontend/src/util/lazyWithReload.ts
new file mode 100644
index 000000000..13a572366
--- /dev/null
+++ b/skyvern-frontend/src/util/lazyWithReload.ts
@@ -0,0 +1,90 @@
+import React from "react";
+
+const CHUNK_LOAD_PATTERNS = [
+ /Failed to fetch dynamically imported module/i,
+ /Importing a module script failed/i,
+ /error loading dynamically imported module/i,
+];
+
+const RELOAD_GUARD_KEY = "skyvern.chunkReloadAt";
+const RELOAD_GUARD_WINDOW_MS = 10_000;
+// Fallback when sessionStorage is unavailable (e.g. private mode or sandboxed
+// iframes that throw on access). Prevents a reload-storm within one session.
+let inMemoryReloadFiredAt = 0;
+
+function isChunkLoadError(error: unknown): boolean {
+ if (!error) return false;
+ const message =
+ error instanceof Error
+ ? error.message
+ : typeof error === "string"
+ ? error
+ : (error as { message?: string })?.message;
+ if (!message) return false;
+ return CHUNK_LOAD_PATTERNS.some((pattern) => pattern.test(message));
+}
+
+function reloadOnce(): void {
+ const now = Date.now();
+ let storageOk = false;
+ try {
+ const last = Number(sessionStorage.getItem(RELOAD_GUARD_KEY) ?? "0");
+ if (now - last < RELOAD_GUARD_WINDOW_MS) return;
+ sessionStorage.setItem(RELOAD_GUARD_KEY, String(now));
+ storageOk = true;
+ } catch {
+ // sessionStorage may be unavailable (private mode, sandboxed iframe).
+ }
+ if (!storageOk) {
+ if (now - inMemoryReloadFiredAt < RELOAD_GUARD_WINDOW_MS) return;
+ inMemoryReloadFiredAt = now;
+ }
+ window.location.reload();
+}
+
+export async function importWithRetry<T>(
+ factory: () => Promise<T>,
+): Promise<T> {
+ try {
+ return await factory();
+ } catch (err) {
+ if (!isChunkLoadError(err)) throw err;
+ try {
+ return await factory();
+ } catch (retryErr) {
+ if (isChunkLoadError(retryErr)) {
+ reloadOnce();
+ // Freeze the loading state; the imminent page reload will resolve this.
+ return new Promise<T>(() => {});
+ }
+ throw retryErr;
+ }
+ }
+}
+
+export function lazyWithReload<T extends React.ComponentType<unknown>>(
+ factory: () => Promise<{ default: T }>,
+): React.LazyExoticComponent<T> {
+ return React.lazy(() => importWithRetry(factory));
+}
+
+export function installChunkLoadErrorHandler(): void {
+ if (typeof window === "undefined") return;
+
+ // Vite emits this when an esmodule preload fails (typically a stale chunk
+ // hash after a deploy). It is not part of the standard WindowEventMap.
+ window.addEventListener(
+ "vite:preloadError" as keyof WindowEventMap,
+ ((event: Event) => {
+ event.preventDefault();
+ reloadOnce();
+ }) as EventListener,
+ );
+
+ window.addEventListener("unhandledrejection", (event) => {
+ if (isChunkLoadError(event.reason)) {
+ event.preventDefault();
+ reloadOnce();
+ }
+ });
+}
diff --git a/skyvern-frontend/src/util/posthogNoiseFilter.test.ts b/skyvern-frontend/src/util/posthogNoiseFilter.test.ts
new file mode 100644
index 000000000..9e32400c7
--- /dev/null
+++ b/skyvern-frontend/src/util/posthogNoiseFilter.test.ts
@@ -0,0 +1,55 @@
+import { describe, expect, it } from "vitest";
+import { dropNoiseExceptions } from "./posthogNoiseFilter";
+
+const baseEvent = {
+ uuid: "test",
+ event: "$exception",
+ properties: {} as Record<string, unknown>,
+};
+
+describe("dropNoiseExceptions", () => {
+ it("drops ResizeObserver loop $exception events", () => {
+ const result = dropNoiseExceptions({
+ ...baseEvent,
+ properties: {
+ $exception_list: [
+ {
+ value:
+ "ResizeObserver loop completed with undelivered notifications.",
+ },
+ ],
+ },
+ });
+ expect(result).toBeNull();
+ });
+
+ it("keeps other $exception events", () => {
+ const event = {
+ ...baseEvent,
+ properties: {
+ $exception_list: [{ value: "TypeError: foo" }],
+ },
+ };
+ expect(dropNoiseExceptions(event)).toBe(event);
+ });
+
+ it("keeps non-exception events", () => {
+ const event = {
+ ...baseEvent,
+ event: "$pageview",
+ };
+ expect(dropNoiseExceptions(event)).toBe(event);
+ });
+
+ it("keeps events with empty exception list", () => {
+ const event = {
+ ...baseEvent,
+ properties: { $exception_list: [] },
+ };
+ expect(dropNoiseExceptions(event)).toBe(event);
+ });
+
+ it("passes null through", () => {
+ expect(dropNoiseExceptions(null)).toBeNull();
+ });
+});
diff --git a/skyvern-frontend/src/util/posthogNoiseFilter.ts b/skyvern-frontend/src/util/posthogNoiseFilter.ts
new file mode 100644
index 000000000..ebffa66f8
--- /dev/null
+++ b/skyvern-frontend/src/util/posthogNoiseFilter.ts
@@ -0,0 +1,23 @@
+import type { BeforeSendFn } from "posthog-js";
+
+type ExceptionEntry = {
+ value?: unknown;
+ type?: unknown;
+};
+
+const NOISE_PATTERNS: ReadonlyArray<RegExp> = [/^ResizeObserver loop /];
+
+function isNoiseException(entry: ExceptionEntry): boolean {
+ const value = entry?.value;
+ if (typeof value !== "string") return false;
+ return NOISE_PATTERNS.some((pattern) => pattern.test(value));
+}
+
+export const dropNoiseExceptions: BeforeSendFn = (event) => {
+ if (!event || event.event !== "$exception") return event;
+ const list = (event.properties?.$exception_list ?? []) as ExceptionEntry[];
+ if (Array.isArray(list) && list.some(isNoiseException)) {
+ return null;
+ }
+ return event;
+};
diff --git a/skyvern-frontend/src/util/sheetsTelemetry.ts b/skyvern-frontend/src/util/sheetsTelemetry.ts
new file mode 100644
index 000000000..fc8ba64ea
--- /dev/null
+++ b/skyvern-frontend/src/util/sheetsTelemetry.ts
@@ -0,0 +1,54 @@
+import { AxiosError } from "axios";
+
+export type SheetsBlockType = "google_sheets_read" | "google_sheets_write";
+
+export async function hashSpreadsheetId(
+ spreadsheetId: string,
+): Promise<string | null> {
+ if (!spreadsheetId) return null;
+ if (typeof crypto === "undefined" || !crypto.subtle) return null;
+ try {
+ const bytes = new TextEncoder().encode(spreadsheetId);
+ const digest = await crypto.subtle.digest("SHA-1", bytes);
+ return Array.from(new Uint8Array(digest))
+ .map((byte) => byte.toString(16).padStart(2, "0"))
+ .join("")
+ .slice(0, 12);
+ } catch {
+ return null;
+ }
+}
+
+export function describeAxiosError(error: unknown): {
+ error_code: string;
+ http_status: number | null;
+ error_message: string;
+} {
+ if (error instanceof AxiosError) {
+ const status = error.response?.status ?? null;
+ const data = error.response?.data as
+ | { error?: string; detail?: string; code?: string }
+ | undefined;
+ const code =
+ data?.code ??
+ data?.error ??
+ (status ? `http_${status}` : (error.code ?? "axios_error"));
+ return {
+ error_code: code,
+ http_status: status,
+ error_message: data?.detail ?? error.message,
+ };
+ }
+ if (error instanceof Error) {
+ return {
+ error_code: "client_error",
+ http_status: null,
+ error_message: error.message,
+ };
+ }
+ return {
+ error_code: "unknown",
+ http_status: null,
+ error_message: "",
+ };
+}