Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(chrome-extension): streamline recording bar into compact draggable badge on recording start

ManthanNimodiya30bf9713c8a7
diff --git a/apps/chrome-extension/src/content/overlay.css b/apps/chrome-extension/src/content/overlay.css
index 7456ae6ab..cdbe0153e 100644
--- a/apps/chrome-extension/src/content/overlay.css
+++ b/apps/chrome-extension/src/content/overlay.css
@@ -1288,3 +1288,194 @@
transform: translateY(0) scale(1);
}
}
+
+.cap-extension-active-recording-container {
+ position: fixed;
+ z-index: 2147483647;
+ display: flex;
+ align-items: center;
+ user-select: none;
+ touch-action: none;
+ animation: cap-extension-badge-in 200ms cubic-bezier(0.16, 1, 0.3, 1);
+}
+
+.cap-extension-active-recording-container.is-dragging {
+ cursor: grabbing;
+}
+
+.cap-extension-recording-badge {
+ position: relative;
+ display: flex;
+ align-items: center;
+ gap: 10px;
+ height: 48px;
+ padding: 6px 14px 6px 6px;
+ border: 1px solid rgba(18, 18, 23, 0.12);
+ border-radius: 9999px;
+ background: rgba(255, 255, 255, 0.98);
+ box-shadow:
+ 0 14px 34px rgba(0, 0, 0, 0.18),
+ 0 4px 12px rgba(0, 0, 0, 0.08);
+ cursor: grab;
+ backdrop-filter: blur(20px);
+ transition:
+ transform 160ms ease,
+ box-shadow 160ms ease,
+ border-color 160ms ease;
+}
+
+.cap-extension-recording-badge.is-counting {
+ width: 48px;
+ padding: 0;
+ justify-content: center;
+ border-color: #ef4444;
+ box-shadow:
+ 0 0 0 4px rgba(239, 68, 68, 0.2),
+ 0 14px 34px rgba(0, 0, 0, 0.18);
+}
+
+.cap-extension-badge-countdown-ring {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ width: 100%;
+ height: 100%;
+}
+
+.cap-extension-badge-countdown-number {
+ font-size: 22px;
+ font-weight: 800;
+ color: #ef4444;
+ line-height: 1;
+ animation: cap-extension-countdown-pop 400ms cubic-bezier(0.16, 1, 0.3, 1);
+}
+
+@keyframes cap-extension-countdown-pop {
+ 0% {
+ transform: scale(0.6);
+ opacity: 0.5;
+ }
+ 50% {
+ transform: scale(1.15);
+ opacity: 1;
+ }
+ 100% {
+ transform: scale(1);
+ opacity: 1;
+ }
+}
+
+.cap-extension-recording-badge:hover {
+ transform: scale(1.05);
+ border-color: rgba(18, 18, 23, 0.25);
+ box-shadow:
+ 0 18px 42px rgba(0, 0, 0, 0.22),
+ 0 4px 12px rgba(0, 0, 0, 0.12);
+}
+
+.cap-extension-recording-badge.is-active {
+ border-color: #3b82f6;
+ box-shadow:
+ 0 0 0 3px rgba(59, 130, 246, 0.25),
+ 0 14px 34px rgba(0, 0, 0, 0.18);
+}
+
+.cap-extension-recording-badge-icon-wrap {
+ position: relative;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ width: 36px;
+ height: 36px;
+}
+
+.cap-extension-recording-badge-logo {
+ width: 32px;
+ height: 32px;
+ border-radius: 50%;
+ object-fit: contain;
+}
+
+.cap-extension-recording-badge-icon-wrap .cap-extension-control-bar-dot {
+ position: absolute;
+ right: -1px;
+ bottom: -1px;
+ width: 10px;
+ height: 10px;
+ border: 2px solid #fff;
+ box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.3);
+}
+
+.cap-extension-recording-badge-time {
+ font-size: 13px;
+ font-weight: 700;
+ font-variant-numeric: tabular-nums;
+ color: #18181b;
+ white-space: nowrap;
+}
+
+.cap-extension-recording-badge-time.is-warning {
+ color: #e5484d;
+}
+
+.cap-extension-recording-popover {
+ position: absolute;
+ bottom: calc(100% + 10px);
+ left: 0;
+ z-index: 10;
+ display: flex;
+ align-items: center;
+ padding: 4px 8px;
+ border: 1px solid rgba(18, 18, 23, 0.1);
+ border-radius: 9999px;
+ background: rgba(255, 255, 255, 0.98);
+ box-shadow:
+ 0 16px 36px rgba(0, 0, 0, 0.2),
+ 0 4px 12px rgba(0, 0, 0, 0.08);
+ backdrop-filter: blur(20px);
+}
+
+.cap-extension-popover-header {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+}
+
+.cap-extension-popover-status {
+ display: flex;
+ align-items: center;
+ gap: 6px;
+}
+
+.cap-extension-popover-grip {
+ color: #a1a1aa;
+ cursor: grab;
+}
+
+.cap-extension-popover-time {
+ font-size: 13px;
+ font-weight: 700;
+ font-variant-numeric: tabular-nums;
+ color: #18181b;
+}
+
+.cap-extension-popover-time.is-warning {
+ color: #e5484d;
+}
+
+.cap-extension-popover-header-actions {
+ display: flex;
+ align-items: center;
+ gap: 4px;
+}
+
+@keyframes cap-extension-badge-in {
+ from {
+ opacity: 0;
+ transform: scale(0.9);
+ }
+ to {
+ opacity: 1;
+ transform: scale(1);
+ }
+}
diff --git a/apps/chrome-extension/src/content/overlay.tsx b/apps/chrome-extension/src/content/overlay.tsx
index 1a55d5a6e..12bb50b00 100644
--- a/apps/chrome-extension/src/content/overlay.tsx
+++ b/apps/chrome-extension/src/content/overlay.tsx
@@ -1,12 +1,4 @@
-import {
- Circle,
- FlipHorizontal,
- Maximize2,
- PictureInPicture,
- RectangleHorizontal,
- Square,
- X,
-} from "lucide-react";
+import { X } from "lucide-react";
import {
type PointerEvent as ReactPointerEvent,
useCallback,
@@ -56,10 +48,6 @@ import { replayStartupMessages, setStartupMessages } from "./startup-messages";
const ROOT_ID = "cap-extension-recorder-overlay";
const WINDOW_PADDING = 20;
const BAR_HEIGHT = 52;
-// The iframe tokens are readable from the host page DOM (they sit in the
-// iframe src), so token checks alone cannot authenticate window messages.
-// Frames we embed always run on the extension origin; require it too.
-const EXTENSION_ORIGIN = new URL(chrome.runtime.getURL("")).origin;
const createSecureToken = () => {
if (typeof crypto.randomUUID === "function") return crypto.randomUUID();
const bytes = new Uint8Array(16);
@@ -73,12 +61,6 @@ const PREVIEW_TOKEN = createSecureToken();
const PREVIEW_URL = chrome.runtime.getURL("camera-preview.html");
const PREVIEW_SRC = `${PREVIEW_URL}#${encodeURIComponent(PREVIEW_TOKEN)}`;
const PREVIEW_ERROR_DELAY_MS = 1200;
-const PANEL_TOKEN = createSecureToken();
-const PANEL_URL = chrome.runtime.getURL("popup.html");
-const PANEL_SRC = `${PANEL_URL}#${encodeURIComponent(PANEL_TOKEN)}`;
-const PANEL_WIDTH = 300;
-const PANEL_DEFAULT_HEIGHT = 460;
-const PANEL_MARGIN = 16;
const CAMERA_MIN_SIZE = 120;
const CAMERA_MAX_SIZE = 420;
const CAMERA_RESIZE_CORNERS = ["nw", "ne", "sw", "se"] as const;
@@ -325,11 +307,6 @@ const connectCameraPreview = async (
peer.close();
throw new Error(response.error);
}
- if (!response.answer) {
- peer.close();
- throw new Error("Camera preview did not return an answer.");
- }
-
await peer.setRemoteDescription(response.answer);
return {
peer,
@@ -337,212 +314,6 @@ const connectCameraPreview = async (
};
};
-type PanelFrameMessage =
- | {
- source: "cap-extension-panel";
- token: string;
- type: "size";
- height: number;
- }
- | {
- source: "cap-extension-panel";
- token: string;
- type: "dismiss";
- };
-
-const isPanelFrameMessage = (value: unknown): value is PanelFrameMessage => {
- if (!value || typeof value !== "object") return false;
- const candidate = value as Partial<PanelFrameMessage>;
- if (
- candidate.source !== "cap-extension-panel" ||
- candidate.token !== PANEL_TOKEN
- ) {
- return false;
- }
- if (candidate.type === "dismiss") return true;
- return (
- candidate.type === "size" &&
- typeof candidate.height === "number" &&
- Number.isFinite(candidate.height)
- );
-};
-
-function RecorderPanelOverlay({
- onDismiss,
- onOpenChange,
-}: {
- onDismiss: () => void;
- onOpenChange: (open: boolean) => void;
-}) {
- const [open, setOpen] = useState(false);
- const [pageVisible, setPageVisible] = useState(
- () => document.visibilityState === "visible",
- );
- const [contentHeight, setContentHeight] = useState(PANEL_DEFAULT_HEIGHT);
- const [viewportHeight, setViewportHeight] = useState(
- () => window.innerHeight,
- );
- const [tokenReady, setTokenReady] = useState(false);
- const startupReplayedRef = useRef(false);
-
- useEffect(() => {
- onOpenChange(open);
- }, [onOpenChange, open]);
-
- useEffect(() => {
- if (!open || tokenReady) return;
- let disposed = false;
- void ensureOverlayTokensRegistered().then((registered) => {
- if (!disposed && registered) setTokenReady(true);
- });
- return () => {
- disposed = true;
- };
- }, [open, tokenReady]);
-
- // The open flag lives in chrome.storage.session so the panel follows the
- // user across tabs: opening or closing it anywhere applies everywhere.
- useEffect(() => {
- let disposed = false;
-
- const syncPanelState = () => {
- loadSharedUiState()
- .then((state) => {
- if (!disposed) setOpen(state.panelOpen);
- })
- .catch(() => undefined);
- };
-
- const handleStorageChange = (
- changes: Record<string, chrome.storage.StorageChange>,
- areaName: string,
- ) => {
- if (areaName === "session" && changes[SHARED_UI_STATE_KEY]) {
- syncPanelState();
- }
- };
-
- syncPanelState();
- chrome.storage.onChanged.addListener(handleStorageChange);
- return () => {
- disposed = true;
- chrome.storage.onChanged.removeListener(handleStorageChange);
- };
- }, []);
-
- useEffect(() => {
- const handleVisibility = () =>
- setPageVisible(document.visibilityState === "visible");
- document.addEventListener("visibilitychange", handleVisibility);
- return () =>
- document.removeEventListener("visibilitychange", handleVisibility);
- }, []);
-
- const closePanel = useCallback(() => {
- setOpen(false);
- onDismiss();
- void updateSharedUiState((current) => ({
- ...current,
- panelOpen: false,
- updatedAt: Date.now(),
- })).catch(() => undefined);
- }, [onDismiss]);
-
- useEffect(() => {
- const handleMessage = (
- message: unknown,
- _sender: chrome.runtime.MessageSender,
- sendResponse: (response?: unknown) => void,
- ) => {
- if (!isOverlayMessage(message)) return false;
- if (message.type === "overlay-panel-toggle") {
- sendResponse({ ok: true });
- // Flip the shared flag; every tab (this one included) follows the
- // storage change. Reopening also resurfaces a dismissed ready bar.
- void updateSharedUiState((current) => ({
- ...current,
- panelOpen: !current.panelOpen,
- readyBarDismissed: current.panelOpen
- ? current.readyBarDismissed
- : false,
- updatedAt: Date.now(),
- }))
- .then((state) => setOpen(state.panelOpen))
- .catch(() => undefined);
- return false;
- }
- if (message.type === "overlay-panel-hide") {
- sendResponse({ ok: true });
- closePanel();
- return false;
- }
- return false;
- };
-
- chrome.runtime.onMessage.addListener(handleMessage);
- if (!startupReplayedRef.current) {
- startupReplayedRef.current = true;
- replayStartupMessages(handleMessage);
- }
- return () => chrome.runtime.onMessage.removeListener(handleMessage);
- }, [closePanel]);
-
- useEffect(() => {
- const handleFrameMessage = (event: MessageEvent<unknown>) => {
- if (event.origin !== EXTENSION_ORIGIN) return;
- if (!isPanelFrameMessage(event.data)) return;
- if (event.data.type === "size") {
- setContentHeight(Math.max(320, Math.ceil(event.data.height)));
- return;
- }
- closePanel();
- };
-
- window.addEventListener("message", handleFrameMessage);
- return () => window.removeEventListener("message", handleFrameMessage);
- }, [closePanel]);
-
- useEffect(() => {
- if (!open) return;
- const handleResize = () => setViewportHeight(window.innerHeight);
- handleResize();
- window.addEventListener("resize", handleResize);
- return () => window.removeEventListener("resize", handleResize);
- }, [open]);
-
- // Only the tab on screen renders the iframe; hidden tabs keep just the
- // shared flag so the panel reappears instantly when they come forward.
- // The iframe also waits for its token registration so the panel page can
- // verify it was embedded by this extension.
- if (!open || !pageVisible || !tokenReady) return null;
-
- const height = Math.min(contentHeight, viewportHeight - PANEL_MARGIN * 2);
-
- return (
- <>
- <button
- type="button"
- className="cap-extension-panel-backdrop"
- aria-label="Dismiss Cap recorder"
- onClick={closePanel}
- />
- <div
- className="cap-extension-panel"
- role="dialog"
- aria-label="Cap recorder"
- style={{ width: `${PANEL_WIDTH}px`, height: `${height}px` }}
- >
- <iframe
- src={PANEL_SRC}
- title="Cap recorder"
- allow="camera; microphone; autoplay"
- className="cap-extension-panel-iframe"
- />
- </div>
- </>
- );
-}
-
function OverlayApp() {
const [extensionSettings, setExtensionSettings] =
useState<ExtensionSettings | null>(null);
@@ -562,7 +333,6 @@ function OverlayApp() {
const [previewError, setPreviewError] = useState<string | null>(null);
const [showPreviewError, setShowPreviewError] = useState(false);
const [iframeReady, setIframeReady] = useState(false);
- const [pipSupported, setPipSupported] = useState(false);
const [parentPipActive, setParentPipActive] = useState(false);
const [framePipActive, setFramePipActive] = useState(false);
const [previewOpen, setPreviewOpen] = useState(false);
@@ -596,11 +366,8 @@ function OverlayApp() {
const previewDismissedRef = useRef(false);
const lastFrameRef = useRef<WebcamPreviewFrame | null>(null);
const lastFrameSavedAtRef = useRef(0);
- const startupReplayedRef = useRef(false);
const webcam = extensionSettings?.webcam ?? null;
- const previewEnabled = Boolean(
- webcam?.enabled && webcam.deviceId && previewOpen,
- );
+ const previewEnabled = Boolean(webcam?.enabled && previewOpen);
const isInPictureInPicture = parentPipActive || framePipActive;
const parentPipSupported =
typeof document !== "undefined" && document.pictureInPictureEnabled;
@@ -685,13 +452,6 @@ function OverlayApp() {
postPreviewMessage,
]);
- const handleRecorderPanelDismiss = useCallback(() => {
- void sendServiceWorkerMessage({
- target: "service-worker",
- type: "close-extension-ui",
- }).catch(() => undefined);
- }, []);
-
const applyWebcamSettings = useCallback(
(getNext: (current: WebcamSettings) => WebcamSettings) => {
setExtensionSettings((current) => {
@@ -869,6 +629,31 @@ function OverlayApp() {
};
}, []);
+ useEffect(() => {
+ let disposed = false;
+ const syncSharedUi = () => {
+ loadSharedUiState()
+ .then((state) => {
+ if (!disposed) setRecorderPanelOpen(state.panelOpen);
+ })
+ .catch(() => undefined);
+ };
+ syncSharedUi();
+ const handleStorageChange = (
+ changes: Record<string, chrome.storage.StorageChange>,
+ areaName: string,
+ ) => {
+ if (areaName === "session" && changes[SHARED_UI_STATE_KEY]) {
+ syncSharedUi();
+ }
+ };
+ chrome.storage.onChanged.addListener(handleStorageChange);
+ return () => {
+ disposed = true;
+ chrome.storage.onChanged.removeListener(handleStorageChange);
+ };
+ }, []);
+
useEffect(() => {
let disposed = false;
@@ -931,6 +716,31 @@ function OverlayApp() {
sendResponse({ ok: true });
+ if (message.type === "overlay-panel-toggle") {
+ void updateSharedUiState((current) => ({
+ ...current,
+ panelOpen: !current.panelOpen,
+ readyBarDismissed: current.panelOpen
+ ? current.readyBarDismissed
+ : false,
+ updatedAt: Date.now(),
+ }))
+ .then((state) => setRecorderPanelOpen(state.panelOpen))
+ .catch(() => undefined);
+ return false;
+ }
+
+ if (message.type === "overlay-panel-hide") {
+ void updateSharedUiState((current) => ({
+ ...current,
+ panelOpen: false,
+ updatedAt: Date.now(),
+ }))
+ .then((state) => setRecorderPanelOpen(state.panelOpen))
+ .catch(() => undefined);
+ return false;
+ }
+
if (message.type === "overlay-hide") {
recordingPreviewActiveRef.current = false;
setRecordingPreviewActive(false);
@@ -1352,7 +1162,6 @@ function OverlayApp() {
return false;
}
- setPipSupported(event.supported);
setFramePipActive(event.active);
return false;
};
@@ -1383,7 +1192,6 @@ function OverlayApp() {
setLivePreviewReady(false);
setPreviewError(null);
setShowPreviewError(false);
- setPipSupported(false);
setFramePipActive(false);
postPreviewMessage({
source: "cap-extension-overlay",
@@ -1608,32 +1416,6 @@ function OverlayApp() {
}).catch(() => undefined);
}, [stopLocalPreview]);
- const updateShape = useCallback(() => {
- applyWebcamSettings((current) => ({
- ...current,
- shape:
- current.shape === "round"
- ? "square"
- : current.shape === "square"
- ? "full"
- : "round",
- }));
- }, [applyWebcamSettings]);
-
- const updateSize = useCallback(() => {
- applyWebcamSettings((current) => ({
- ...current,
- size: current.size <= 230 ? 400 : 230,
- }));
- }, [applyWebcamSettings]);
-
- const updateMirror = useCallback(() => {
- applyWebcamSettings((current) => ({
- ...current,
- mirror: !current.mirror,
- }));
- }, [applyWebcamSettings]);
-
const handleTogglePictureInPicture = useCallback(() => {
const video = pipVideoRef.current;
if (video && document.pictureInPictureElement === video) {
@@ -1724,94 +1506,6 @@ function OverlayApp() {
className="cap-extension-camera-shell"
style={{ borderRadius }}
>
- <div className="cap-extension-camera-bar">
- <div
- data-controls
- className="cap-extension-camera-controls"
- role="toolbar"
- aria-label="Camera preview controls"
- onPointerDown={(event) => event.stopPropagation()}
- onClick={(event) => event.stopPropagation()}
- onKeyDown={(event) => {
- if (event.key === "Escape") {
- event.stopPropagation();
- handleClose();
- }
- }}
- >
- <button
- type="button"
- className="cap-extension-camera-control"
- aria-label="Close camera preview"
- title="Close"
- onClick={handleClose}
- >
- <X size={22} aria-hidden />
- </button>
- <button
- type="button"
- className={classNames(
- "cap-extension-camera-control",
- webcam.size > 230 && "is-active",
- )}
- aria-label="Resize camera preview"
- title="Resize"
- onClick={updateSize}
- >
- <Maximize2 size={22} aria-hidden />
- </button>
- <button
- type="button"
- className={classNames(
- "cap-extension-camera-control",
- webcam.shape !== "round" && "is-active",
- )}
- aria-label="Change camera preview shape"
- title="Shape"
- onClick={updateShape}
- >
- {webcam.shape === "round" ? (
- <Circle size={22} aria-hidden />
- ) : null}
- {webcam.shape === "square" ? (
- <Square size={22} aria-hidden />
- ) : null}
- {webcam.shape === "full" ? (
- <RectangleHorizontal size={22} aria-hidden />
- ) : null}
- </button>
- <button
- type="button"
- className={classNames(
- "cap-extension-camera-control",
- webcam.mirror && "is-active",
- )}
- aria-label="Mirror camera preview"
- title="Mirror"
- onClick={updateMirror}
- >
- <FlipHorizontal size={22} aria-hidden />
- </button>
- <button
- type="button"
- className={classNames(
- "cap-extension-camera-control",
- isInPictureInPicture && "is-active",
- )}
- aria-label="Toggle Picture in Picture"
- title={
- parentPipSupported || pipSupported
- ? "Picture in Picture"
- : "Picture in Picture is blocked on this page"
- }
- disabled={!parentPipSupported && !pipSupported}
- onClick={handleTogglePictureInPicture}
- >
- <PictureInPicture size={22} aria-hidden />
- </button>
- </div>
- </div>
-
<div
ref={cameraFrameRef}
className={classNames(
@@ -1826,6 +1520,19 @@ function OverlayApp() {
borderRadius,
}}
>
+ <button
+ type="button"
+ className="cap-extension-camera-dismiss-btn"
+ aria-label="Close camera preview"
+ title="Close camera"
+ data-controls
+ onClick={(e) => {
+ e.stopPropagation();
+ handleClose();
+ }}
+ >
+ <X size={14} aria-hidden />
+ </button>
{lastPreviewFrame ? (
<img
src={lastPreviewFrame.dataUrl}
@@ -1908,10 +1615,6 @@ function OverlayApp() {
disablePictureInPicture={false}
controlsList="nodownload nofullscreen noremoteplayback"
/>
- <RecorderPanelOverlay
- onDismiss={handleRecorderPanelDismiss}
- onOpenChange={setRecorderPanelOpen}
- />
<RecordingBarOverlay recorderPanelOpen={recorderPanelOpen} />
<CountdownOverlay />
<ConfirmOverlay />
diff --git a/apps/chrome-extension/src/content/recording-bar.tsx b/apps/chrome-extension/src/content/recording-bar.tsx
index 6a1e46ee7..0fb44cf84 100644
--- a/apps/chrome-extension/src/content/recording-bar.tsx
+++ b/apps/chrome-extension/src/content/recording-bar.tsx
@@ -35,9 +35,6 @@ import { DrawingOverlay } from "./drawing-overlay";
const EDGE_PADDING = 16;
const BOTTOM_OFFSET = 28;
-// Live updates arrive via status broadcasts and the session-storage mirror;
-// this poll only reconciles drift, so it can be slow instead of hammering the
-// service worker (and through it the offscreen document) from every tab.
const POLL_INTERVAL_MS = 5000;
const WARNING_THRESHOLD_MS = 60_000;
const LOGO_URL = chrome.runtime.getURL("icons/icon-48.png");
@@ -77,8 +74,6 @@ const toOverlayPosition = (position: {
updatedAt: Date.now(),
});
-// The timer derives from wall-clock deltas against the shared status, so as
-// long as every tab holds the same status object their clocks read the same.
const currentDurationMs = (status: BarStatus, now: number) =>
status.phase === "recording"
? status.durationMs + Math.max(0, now - status.updatedAt)
@@ -91,6 +86,7 @@ export function RecordingBarOverlay({
const [plan, setPlan] = useState<RecordingPlan | null>(null);
const [signedIn, setSignedIn] = useState(false);
const [readyDismissed, setReadyDismissed] = useState(false);
+ const [countdownValue, setCountdownValue] = useState<number | null>(null);
const [position, setPosition] = useState<{ x: number; y: number } | null>(
null,
);
@@ -99,8 +95,12 @@ export function RecordingBarOverlay({
const [isDragging, setIsDragging] = useState(false);
const [busy, setBusy] = useState(false);
const [drawing, setDrawing] = useState(false);
+ const [isExpanded, setIsExpanded] = useState(false);
const [now, setNow] = useState(() => Date.now());
const dragOffsetRef = useRef({ x: 0, y: 0 });
+ const dragDistanceRef = useRef(0);
+ const dragStartPosRef = useRef({ x: 0, y: 0 });
+ const isPointerDownRef = useRef(false);
const barRef = useRef<HTMLDivElement>(null);
const planRef = useRef<RecordingPlan | null>(null);
const positionRef = useRef<{ x: number; y: number } | null>(null);
@@ -154,10 +154,6 @@ export function RecordingBarOverlay({
recorderPanelOpenRef.current = recorderPanelOpen;
}, [recorderPanelOpen, refresh]);
- // chrome.storage.session is the cross-tab source of truth for both the
- // recording state and the shared UI flags; the storage change events reach
- // every tab (including backgrounded ones), which keeps each bar in lockstep
- // without per-tab polling round-trips.
useEffect(() => {
let disposed = false;
@@ -227,11 +223,6 @@ export function RecordingBarOverlay({
useEffect(() => {
const handleVisibility = () => {
if (document.visibilityState !== "visible") return;
- // Recompute the clock immediately so the first painted frame after a
- // tab switch already shows the right time, then reconcile from the
- // session-storage mirror: reading storage does not wake the service
- // worker, unlike a get-recording-status round trip, and the slow
- // poll below still corrects any drift while the bar is active.
setNow(Date.now());
loadSharedRecordingState()
.then((state) => applySharedState(state))
@@ -249,59 +240,82 @@ export function RecordingBarOverlay({
if (!planRef.current) refresh();
return false;
}
- if (!isOverlayMessage(message)) return false;
- refresh();
+ if (isOverlayMessage(message)) {
+ if (message.type === "overlay-countdown") {
+ setCountdownValue(message.seconds);
+ let cur = message.seconds;
+ const perNum = message.durationMs / message.seconds;
+ const interval = window.setInterval(() => {
+ cur -= 1;
+ if (cur <= 0) {
+ window.clearInterval(interval);
+ setCountdownValue(null);
+ return;
+ }
+ setCountdownValue(cur);
+ }, perNum);
+ return false;
+ }
+ if (message.type === "overlay-hide") {
+ setCountdownValue(null);
+ refresh();
+ return false;
+ }
+ refresh();
+ return false;
+ }
return false;
};
chrome.runtime.onMessage.addListener(handleMessage);
return () => chrome.runtime.onMessage.removeListener(handleMessage);
}, [applyResponse, refresh]);
- const active = status !== null;
- // The "Ready to record" bar only makes sense once the user can actually
- // start a recording, which requires being signed in.
+ const active = status !== null || countdownValue !== null;
const ready = signedIn && !active && recorderPanelOpen && !readyDismissed;
const visible = active || ready;
- // Drawing is reachable only from a visible bar, so once the bar hides
- // (recording stopped and the ready bar dismissed) tear the canvas down too
- // rather than leaving an invisible surface armed to swallow page clicks.
useEffect(() => {
- if (!visible) setDrawing(false);
+ if (!visible) {
+ setDrawing(false);
+ setIsExpanded(false);
+ }
}, [visible]);
useEffect(() => {
- if (!active) return;
+ if (status === null) return;
setNow(Date.now());
const interval = window.setInterval(() => setNow(Date.now()), 500);
return () => window.clearInterval(interval);
- }, [active]);
+ }, [status]);
useEffect(() => {
- if (!active) return;
+ if (status === null) return;
const interval = window.setInterval(() => {
if (document.visibilityState === "visible") refresh();
}, POLL_INTERVAL_MS);
return () => window.clearInterval(interval);
- }, [active, refresh]);
-
- const clampToViewport = useCallback((value: { x: number; y: number }) => {
- const rect = barRef.current?.getBoundingClientRect();
- const width = rect?.width ?? 360;
- const height = rect?.height ?? 64;
- const maxX = Math.max(
- EDGE_PADDING,
- window.innerWidth - width - EDGE_PADDING,
- );
- const maxY = Math.max(
- EDGE_PADDING,
- window.innerHeight - height - EDGE_PADDING,
- );
- return {
- x: Math.min(Math.max(value.x, EDGE_PADDING), maxX),
- y: Math.min(Math.max(value.y, EDGE_PADDING), maxY),
- };
- }, []);
+ }, [status, refresh]);
+
+ const clampToViewport = useCallback(
+ (value: { x: number; y: number }) => {
+ const rect = barRef.current?.getBoundingClientRect();
+ const width = rect?.width ?? (active ? 60 : 380);
+ const height = rect?.height ?? (active ? 60 : 64);
+ const maxX = Math.max(
+ EDGE_PADDING,
+ window.innerWidth - width - EDGE_PADDING,
+ );
+ const maxY = Math.max(
+ EDGE_PADDING,
+ window.innerHeight - height - EDGE_PADDING,
+ );
+ return {
+ x: Math.min(Math.max(value.x, EDGE_PADDING), maxX),
+ y: Math.min(Math.max(value.y, EDGE_PADDING), maxY),
+ };
+ },
+ [active],
+ );
useEffect(() => {
if (!visible || isDragging) return;
@@ -324,7 +338,7 @@ export function RecordingBarOverlay({
(active
? {
x: EDGE_PADDING,
- y: (window.innerHeight - rect.height) / 2,
+ y: window.innerHeight - 90,
}
: {
x: (window.innerWidth - rect.width) / 2,
@@ -354,12 +368,9 @@ export function RecordingBarOverlay({
const handlePointerDown = useCallback(
(event: ReactPointerEvent<HTMLDivElement>) => {
if ((event.target as HTMLElement).closest("[data-controls]")) return;
- event.preventDefault();
- event.stopPropagation();
- // Capture the pointer so the drag survives the cursor crossing
- // iframes (for example the camera preview) on the page.
- event.currentTarget.setPointerCapture(event.pointerId);
- setIsDragging(true);
+ isPointerDownRef.current = true;
+ dragDistanceRef.current = 0;
+ dragStartPosRef.current = { x: event.clientX, y: event.clientY };
dragOffsetRef.current = {
x: event.clientX - (position?.x ?? EDGE_PADDING),
y: event.clientY - (position?.y ?? EDGE_PADDING),
@@ -369,16 +380,33 @@ export function RecordingBarOverlay({
);
useEffect(() => {
- if (!isDragging) return;
const handlePointerMove = (event: PointerEvent) => {
- setPosition(
- clampToViewport({
- x: event.clientX - dragOffsetRef.current.x,
- y: event.clientY - dragOffsetRef.current.y,
- }),
+ if (!isPointerDownRef.current) return;
+ const dist = Math.hypot(
+ event.clientX - dragStartPosRef.current.x,
+ event.clientY - dragStartPosRef.current.y,
);
+ dragDistanceRef.current = dist;
+ if (dist > 4) {
+ setIsDragging(true);
+ setPosition(
+ clampToViewport({
+ x: event.clientX - dragOffsetRef.current.x,
+ y: event.clientY - dragOffsetRef.current.y,
+ }),
+ );
+ }
};
- const handlePointerUp = () => {
+
+ const handlePointerUp = (event: PointerEvent) => {
+ if (!isPointerDownRef.current) return;
+ isPointerDownRef.current = false;
+ if (dragDistanceRef.current < 5) {
+ const target = event.target as HTMLElement | null;
+ if (target && !target.closest("[data-controls]")) {
+ setIsExpanded((current) => !current);
+ }
+ }
setIsDragging(false);
const nextPosition = positionRef.current;
if (!nextPosition) return;
@@ -389,6 +417,7 @@ export function RecordingBarOverlay({
.then((state) => setPersistedBarPosition(state.recordingBarPosition))
.catch(() => undefined);
};
+
window.addEventListener("pointermove", handlePointerMove);
window.addEventListener("pointerup", handlePointerUp);
window.addEventListener("pointercancel", handlePointerUp);
@@ -397,7 +426,7 @@ export function RecordingBarOverlay({
window.removeEventListener("pointerup", handlePointerUp);
window.removeEventListener("pointercancel", handlePointerUp);
};
- }, [clampToViewport, isDragging]);
+ }, [clampToViewport]);
const sendControl = useCallback(
(type: BarControl) => {
@@ -443,7 +472,7 @@ export function RecordingBarOverlay({
if (!visible) return null;
- if (status === null) {
+ if (status === null && countdownValue === null) {
return (
<>
<div
@@ -481,17 +510,10 @@ export function RecordingBarOverlay({
</span>
</div>
</div>
+
<div className="cap-extension-control-bar-divider" aria-hidden />
+
<div className="cap-extension-control-bar-actions" data-controls>
- <button
- type="button"
- className="cap-extension-control-bar-pill is-start"
- disabled={busy}
- onClick={startRecording}
- >
- <Play size={14} fill="currentColor" strokeWidth={0} aria-hidden />
- Start recording
- </button>
<button
type="button"
className={classNames(
@@ -503,8 +525,19 @@ export function RecordingBarOverlay({
title="Draw on the page"
onClick={toggleDrawing}
>
- <Pencil size={18} aria-hidden />
+ <Pencil size={17} aria-hidden />
+ </button>
+
+ <button
+ type="button"
+ className="cap-extension-control-bar-pill is-start"
+ disabled={busy}
+ onClick={startRecording}
+ >
+ <Play size={13} fill="currentColor" strokeWidth={0} aria-hidden />
+ Start recording
</button>
+
<button
type="button"
className="cap-extension-control-bar-icon-button is-quiet"
@@ -512,7 +545,7 @@ export function RecordingBarOverlay({
title="Hide bar"
onClick={dismissReadyBar}
>
- <X size={20} aria-hidden />
+ <X size={18} aria-hidden />
</button>
</div>
</div>
@@ -521,29 +554,25 @@ export function RecordingBarOverlay({
);
}
- const isPaused = status.phase === "paused";
+ const isPaused = status?.phase === "paused";
const maxMs =
plan && !plan.isPro && plan.maxRecordingSeconds !== null
? plan.maxRecordingSeconds * 1000
: null;
- const durationMs = currentDurationMs(status, now);
+ const durationMs = status ? currentDurationMs(status, now) : 0;
const displayMs =
maxMs !== null ? Math.max(0, maxMs - durationMs) : durationMs;
const isWarning = maxMs !== null && displayMs <= WARNING_THRESHOLD_MS;
- const actionsOpenLeft =
- position !== null && position.x > window.innerWidth / 2;
return (
<>
<div
ref={barRef}
className={classNames(
- "cap-extension-recording-rail",
+ "cap-extension-active-recording-container",
isDragging && "is-dragging",
- actionsOpenLeft && "opens-left",
+ isExpanded && "is-expanded",
)}
- role="toolbar"
- aria-label="Cap recording controls"
style={{
left: `${position?.x ?? EDGE_PADDING}px`,
top: position ? `${position.y}px` : "50%",
@@ -551,86 +580,138 @@ export function RecordingBarOverlay({
}}
onPointerDown={handlePointerDown}
>
- <div
- className={classNames(
- "cap-extension-recording-rail-timer",
- isWarning && "is-warning",
- )}
- data-drag-handle
- title="Drag recording controls"
- >
- <GripVertical
- className="cap-extension-recording-rail-grip"
- size={14}
- aria-hidden
- />
- <span
- className={classNames(
- "cap-extension-control-bar-dot",
- isPaused ? "is-paused" : "is-recording",
- )}
- aria-hidden
- />
- <span
- className="cap-extension-recording-rail-time"
- data-recording-time
- >
- {formatDuration(displayMs)}
- </span>
- </div>
<button
type="button"
- className="cap-extension-control-bar-pill is-stop is-compact"
- aria-label="Stop recording"
- title="Stop recording"
- disabled={busy}
- data-controls
- onClick={() => sendControl("stop-recording")}
- >
- <Square size={12} fill="currentColor" strokeWidth={0} aria-hidden />
- </button>
- <div
- className="cap-extension-recording-rail-actions"
- data-controls
- data-recording-actions
+ className={classNames(
+ "cap-extension-recording-badge",
+ countdownValue !== null && "is-counting",
+ isPaused && "is-paused",
+ isExpanded && "is-active",
+ )}
+ aria-label={
+ isExpanded ? "Close recording menu" : "Open recording menu"
+ }
+ title={isExpanded ? "Close menu" : "Recording menu"}
>
- <button
- type="button"
- className="cap-extension-control-bar-icon-button is-compact"
- aria-label={isPaused ? "Resume recording" : "Pause recording"}
- title={isPaused ? "Resume" : "Pause"}
- disabled={busy}
- data-recording-pause
- onClick={() =>
- sendControl(isPaused ? "resume-recording" : "pause-recording")
- }
- >
- {isPaused ? (
- <Play size={16} fill="currentColor" strokeWidth={0} aria-hidden />
+ <div className="cap-extension-recording-badge-icon-wrap">
+ {countdownValue !== null ? (
+ <div className="cap-extension-badge-countdown-ring">
+ <span className="cap-extension-badge-countdown-number">
+ {countdownValue}
+ </span>
+ </div>
) : (
- <Pause
- size={16}
- fill="currentColor"
- strokeWidth={0}
- aria-hidden
- />
- )}
- </button>
- <button
- type="button"
- className={classNames(
- "cap-extension-control-bar-icon-button is-compact",
- drawing && "is-active",
+ <>
+ <img
+ className="cap-extension-recording-badge-logo"
+ src={LOGO_URL}
+ alt=""
+ draggable={false}
+ />
+ <span
+ className={classNames(
+ "cap-extension-control-bar-dot",
+ isPaused ? "is-paused" : "is-recording",
+ )}
+ aria-hidden
+ />
+ </>
)}
- aria-label="Draw on the page"
- aria-pressed={drawing}
- title="Draw on the page"
- onClick={toggleDrawing}
+ </div>
+
+ {countdownValue === null && status ? (
+ <span
+ className={classNames(
+ "cap-extension-recording-badge-time",
+ isWarning && "is-warning",
+ )}
+ >
+ {formatDuration(displayMs)}
+ </span>
+ ) : null}
+ </button>
+
+ {isExpanded && status !== null ? (
+ <div
+ className="cap-extension-recording-popover"
+ role="dialog"
+ aria-label="Recording options"
+ data-controls
>
- <Pencil size={16} aria-hidden />
- </button>
- </div>
+ <div className="cap-extension-popover-header">
+ <div className="cap-extension-popover-status">
+ <GripVertical
+ className="cap-extension-popover-grip"
+ size={14}
+ aria-hidden
+ />
+ <span
+ className={classNames(
+ "cap-extension-control-bar-dot",
+ isPaused ? "is-paused" : "is-recording",
+ )}
+ aria-hidden
+ />
+ <span
+ className={classNames(
+ "cap-extension-popover-time",
+ isWarning && "is-warning",
+ )}
+ >
+ {formatDuration(displayMs)}
+ </span>
+ </div>
+
+ <div className="cap-extension-popover-header-actions">
+ <button
+ type="button"
+ className="cap-extension-control-bar-icon-button is-compact"
+ aria-label={isPaused ? "Resume recording" : "Pause recording"}
+ title={isPaused ? "Resume" : "Pause"}
+ disabled={busy}
+ onClick={() =>
+ sendControl(
+ isPaused ? "resume-recording" : "pause-recording",
+ )
+ }
+ >
+ {isPaused ? (
+ <Play
+ size={14}
+ fill="currentColor"
+ strokeWidth={0}
+ aria-hidden
+ />
+ ) : (
+ <Pause
+ size={14}
+ fill="currentColor"
+ strokeWidth={0}
+ aria-hidden
+ />
+ )}
+ </button>
+ <button
+ type="button"
+ className="cap-extension-control-bar-icon-button is-compact is-quiet"
+ aria-label="Stop recording"
+ title="Stop recording"
+ disabled={busy}
+ onClick={() => sendControl("stop-recording")}
+ >
+ <Square
+ size={13}
+ fill="currentColor"
+ strokeWidth={0}
+ aria-hidden
+ />
+ </button>
+ </div>
+ </div>
+ </div>
+ ) : null}
</div>
+
<DrawingOverlay active={drawing} onClose={stopDrawing} />
</>
);