wavetermdev/waveterm · error
Invalid data URL
Error message
Invalid data URL
What it means
parseDataUrl parses data: URLs into a mime type and byte buffer. It strictly requires the string to begin with the "data:" scheme; anything else is rejected with this error because it cannot be interpreted as a data URL.
Source
Thrown at frontend/util/util.ts:452
return "\\f";
}
if (code === 0x1b) return "\\x1b"; // escape
if (code < 0x20 || code === 0x7f) return `\\x${code.toString(16).padStart(2, "0")}`;
return ch;
});
}
function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
type ParsedDataUrl = {
mimeType: string;
buffer: Uint8Array;
};
function parseDataUrl(dataUrl: string): ParsedDataUrl {
if (!dataUrl.startsWith("data:")) throw new Error("Invalid data URL");
const [header, data] = dataUrl.split(",", 2);
if (data === undefined) throw new Error("Invalid data URL: missing data");
const meta = header.slice(5);
let mimeType = "text/plain;charset=US-ASCII";
const parts = meta.split(";");
if (parts[0]) mimeType = parts[0];
const isBase64 = parts.some((p) => p.toLowerCase() === "base64");
let buffer: Uint8Array;
if (isBase64) {
buffer = base64ToArray(data);
} else {
// assume text
const decoded = decodeURIComponent(data);
buffer = new TextEncoder().encode(decoded);
}
View on GitHub (pinned to a4447c1563)
Solutions
- Inspect the input string; confirm it starts with "data:".
- If you only have raw base64, wrap it: `data:${mimeType};base64,${raw}`.
- Skip the call for non-data URLs (check startsWith) and handle them through a different path.
- Verify the source of the string (upload, clipboard, config) is producing a full data URL.
Example fix
// before
const parsedUrl = parsed(imageSrc); // imageSrc = "iVBORw0KGgo..."
// after
const dataUrl = imageSrc.startsWith("data:") ? imageSrc : `data:image/png;base64,${imageSrc}`;
const parsedUrl = parsed(dataUrl); Defensive patterns
Strategy: type-guard
Validate before calling
if (typeof input === "string" && input.startsWith("data:")) {
const result = parsed(input);
} else {
// treat as regular URL or raw base64, route accordingly
} Type guard
function isDataUrl(s: unknown): s is string {
return typeof s === "string" && s.startsWith("data:");
} Try / catch
try {
return parsed(dataUrl);
} catch (e) {
if (String(e.message).startsWith("Invalid data URL")) {
console.warn("not a data URL:", dataUrl.slice(0, 32));
return null;
}
throw e;
} Prevention
- Always check startsWith("data:") before parsing image/src strings that could be plain URLs.
- When persisting images, store the full data URL, not just the base64 payload.
- Normalize inputs (trim, add scheme) at ingestion boundaries.
When it happens
Trigger: Calling parseDataUrl (via the parsed helper) with a plain http(s) URL, a bare base64 string, an empty string, or a data URL that lost its scheme after trimming/splitting.
Common situations: Storing only the base64 payload in a config and forgetting the "data:" prefix, copying an <img src> that was a normal URL, or string processing that stripped the prefix.
Related errors
- Invalid data URL: missing data
- invalid data URL: must start with 'data:'
- tabid and blockid are required
- Block not found: ${blockId}
- Block not found in tab: ${blockId}
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/76c6d1313daaea82.
Report an issue: GitHub.