Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ function removeCaptureOverlay(): void {
captureOverlay = null;
}

/**
* Run after the next paint. A single rAF fires *before* the frame is painted,
* so the overlay's display change would not yet be on screen; a second rAF
* guarantees the change has been painted before we report back — otherwise the
* notice can leak into the captured frame.
*/
function afterPaint(callback: () => void): void {
window.requestAnimationFrame(() => window.requestAnimationFrame(callback));
}

chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => {
if (message?.type === "SB_CAPTURE_BEGIN") {
ensureCaptureOverlay().style.display = "flex";
Expand All @@ -103,7 +113,8 @@ chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => {

if (message?.type === "SB_SET_OVERLAY") {
setCaptureOverlayDisplay(Boolean(message.visible));
window.requestAnimationFrame(() => sendResponse({ ok: true }));
// Wait for the hide/show to actually paint before the orchestrator captures.
afterPaint(() => sendResponse({ ok: true }));
return true;
}

Expand Down
3 changes: 3 additions & 0 deletions src/lib/capture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ export async function captureFullPage(
await sendMessage(tabId, { type: "SB_SCROLL_TO", y });
await wait(120);
// Hide the notice so it is not baked into this frame, then capture.
// notify resolves only after the hide has painted (double-rAF in the
// content script); a short extra settle covers compositor lag.
await notify(tabId, { type: "SB_SET_OVERLAY", visible: false });
await wait(60);
const dataUrl = await chrome.tabs.captureVisibleTab(windowId, { format: "png" });
segments.push({ y, dataUrl });
onProgress?.(i + 1, steps.length);
Expand Down
Loading