Repository navigation
fix(web): keep desktop annotation screenshots under CSP #12636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
juliusmarminge
merged 1 commit into
pingdotgg:main
from
cestercian:cursor/fix-annotation-screenshot-csp-b61e
Sep 19, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,49 +1,30 @@ | ||
| import type { PreviewAnnotationPayload } from "@t3tools/contracts"; | ||
|
|
||
| async function previewAnnotationScreenshotFile( | ||
| annotation: PreviewAnnotationPayload, | ||
| ): Promise<File | null> { | ||
| if (!annotation.screenshot) return null; | ||
| const response = await fetch(annotation.screenshot.dataUrl); | ||
| const blob = await response.blob(); | ||
| return new File([blob], `preview-annotation-${annotation.id}.png`, { | ||
| type: blob.type || "image/png", | ||
| }); | ||
| } | ||
|
|
||
| /** Upper bound on turning a picked element's crop into a composer attachment. */ | ||
| const PREVIEW_ANNOTATION_CAPTURE_TIMEOUT_MS = 5_000; | ||
| import { dataUrlToFile } from "./imageCompression"; | ||
|
|
||
| export type PreviewAnnotationCapture = | ||
| /** The crop is ready to attach. */ | ||
| | { readonly status: "captured"; readonly file: File } | ||
| /** The pick carried no crop, which is normal for comment-only annotations. */ | ||
| | { readonly status: "none" } | ||
| /** The crop stalled or threw. Send the annotation without it. */ | ||
| /** The crop could not be decoded. Send the annotation without it. */ | ||
| | { readonly status: "failed" }; | ||
|
|
||
| /** | ||
| * Bounded wrapper around `previewAnnotationScreenshotFile`. The picker holds the | ||
| * composer while this runs, so it must always settle: a stalled crop resolves as | ||
| * `failed` instead of leaving the caller waiting. | ||
| */ | ||
| export async function capturePreviewAnnotationScreenshot( | ||
| const PNG_DATA_URL_PREFIX = "data:image/png;base64,"; | ||
|
|
||
| /** Decode Electron's PNG crop locally; fetching a data URL violates desktop connect-src. */ | ||
| export function capturePreviewAnnotationScreenshot( | ||
| annotation: PreviewAnnotationPayload, | ||
| timeoutMs: number = PREVIEW_ANNOTATION_CAPTURE_TIMEOUT_MS, | ||
| ): Promise<PreviewAnnotationCapture> { | ||
| ): PreviewAnnotationCapture { | ||
| if (!annotation.screenshot) return { status: "none" }; | ||
| let timer: ReturnType<typeof setTimeout> | undefined; | ||
| try { | ||
| const file = await Promise.race([ | ||
| previewAnnotationScreenshotFile(annotation), | ||
| new Promise<null>((resolve) => { | ||
| timer = setTimeout(() => resolve(null), timeoutMs); | ||
| }), | ||
| ]); | ||
| return file ? { status: "captured", file } : { status: "failed" }; | ||
| const { dataUrl } = annotation.screenshot; | ||
| if (!dataUrl.startsWith(PNG_DATA_URL_PREFIX)) { | ||
| return { status: "failed" }; | ||
| } | ||
| const file = dataUrlToFile(dataUrl, `preview-annotation-${annotation.id}.png`, "image/png"); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| return file.size > 0 ? { status: "captured", file } : { status: "failed" }; | ||
| } catch { | ||
| return { status: "failed" }; | ||
| } finally { | ||
| clearTimeout(timer); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.