fix: improve error message when exporting long conversations as image

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
xintaofei
2026-04-03 23:38:25 +08:00
parent 40d0a4b995
commit 32a1c5adc0
12 changed files with 33 additions and 6 deletions

View File

@@ -445,6 +445,13 @@ export function exportAsHtml(data: ExportConversationData): void {
// Safari caps at 16384, Chrome at ~32767. Use a safe limit.
const MAX_IMAGE_HEIGHT = 16000
export class ExportTooLongError extends Error {
constructor() {
super("Content too long for image export")
this.name = "ExportTooLongError"
}
}
export async function exportAsImage(
data: ExportConversationData
): Promise<void> {
@@ -477,11 +484,16 @@ export async function exportAsImage(
})
const target = iframeDoc.querySelector(".container") ?? body
const dataUrl = await toPng(target as HTMLElement, {
width: 800,
pixelRatio: 2,
backgroundColor: "#f9fafb",
})
let dataUrl: string
try {
dataUrl = await toPng(target as HTMLElement, {
width: 800,
pixelRatio: 2,
backgroundColor: "#f9fafb",
})
} catch {
throw new ExportTooLongError()
}
const res = await fetch(dataUrl)
const blob = await res.blob()
const url = URL.createObjectURL(blob)