The free and privacy-friendly screen recorder with no limits 🎥
JavaScript annotationannotation-toolaudiocamerachrome-extensiondesigneditorffmpegjavascriptproductivityrecorderscreen-capturescreen-recorderscreencasttensorflowvideo
Reinstate the "Share this tab instead" button + letterbox fix when switching tab streams mid-recording
Alyssa X85736c323864
diff --git a/package.json b/package.jsonindex a462958..3be9a38 100755--- a/package.json+++ b/package.json@@ -1,6 +1,6 @@{"name": "screenity",- "version": "4.5.5",+ "version": "4.5.6","description": "The free and privacy-friendly screen recorder with no sign in needed.","scripts": {"build": "cross-env NODE_ENV=production node utils/build.js",diff --git a/src/manifest.json b/src/manifest.jsonindex bfcf6c1..8305ece 100755--- a/src/manifest.json+++ b/src/manifest.json@@ -3,7 +3,7 @@"name": "__MSG_extName__","description": "__MSG_extDesc__","default_locale": "en",- "version": "4.5.5",+ "version": "4.5.6","background": {"service_worker": "background.bundle.js"},diff --git a/src/pages/CloudRecorder/CloudRecorder.jsx b/src/pages/CloudRecorder/CloudRecorder.jsxindex 548578d..ade3fcc 100644--- a/src/pages/CloudRecorder/CloudRecorder.jsx+++ b/src/pages/CloudRecorder/CloudRecorder.jsx@@ -19,7 +19,10 @@ import {import { traceStep } from "../utils/startFlowTrace";import { IS_OFFSCREEN_HOST } from "../utils/recordingHost";import { sendSystemAudioGuidanceToast } from "../utils/systemAudioGuidance";-import { shouldUseDisplayMediaForScreen } from "../utils/screenCaptureMode";+import {+ shouldUseDisplayMediaForScreen,+ screenSurfaceSwitching,+} from "../utils/screenCaptureMode";import { acquireDisplayMediaWithFocusRetry } from "../utils/acquireDisplayMedia";import { startPrewarm, stopPrewarm } from "../Recorder/streamWarmup";import { preloadWebCodecsModules } from "../Recorder/webcodecs/WebCodecsRecorder";@@ -6112,6 +6115,8 @@ const CloudRecorder = () => {const targetHeight = height;const isTabModeRequest =data.recordingType === "region" || isTab.current;+ const { disableSurfaceSwitching } =+ await chrome.storage.local.get(["disableSurfaceSwitching"]);const displayConstraints = {audio: data.systemAudio ? true : false,video: {@@ -6122,14 +6127,16 @@ const CloudRecorder = () => {// tab/region. Hint only; the user can still switch panes.displaySurface: isTabModeRequest ? "browser" : "monitor",},- // systemAudio:"include" (default may hide the toggle);- // surfaceSwitching:"exclude" dodges crbug 344876285 (switch ends- // mac audio). Screen-only; these throw TypeError w/ preferCurrentTab.+ // systemAudio:"include" (default may hide the toggle).+ // surfaceSwitching keeps Chrome's "Share this tab instead" button.+ // Screen-only; these throw TypeError w/ preferCurrentTab....(isTabModeRequest? {}: {systemAudio: "include",- surfaceSwitching: "exclude",+ surfaceSwitching: screenSurfaceSwitching({+ disableSurfaceSwitching,+ }),selfBrowserSurface: "exclude",}),};@@ -6300,6 +6307,34 @@ const CloudRecorder = () => {instantMode: instantMode.current || false,});+ // A surface switch swaps the source in place: the track stays live, so+ // nothing above re-runs and anything read from getSettings() goes+ // stale. The cursor overlay maps click coords against `surface`, so a+ // stale one misplaces click effects for the rest of the recording.+ let boundSurface = surface;+ track.addEventListener("configurationchange", () => {+ const next = track.getSettings();+ chrome.storage.local.set({+ surface: next.displaySurface,+ recordedStreamDimensions: {+ width: next.width,+ height: next.height,+ },+ });+ if (next.displaySurface === boundSurface) return;+ traceStep("surfaceSwitched", {+ from: boundSurface || null,+ to: next.displaySurface || null,+ });+ boundSurface = next.displaySurface;+ chrome.runtime.sendMessage({+ type: "set-surface",+ surface: next.displaySurface,+ subscribed: true,+ instantMode: instantMode.current || false,+ });+ });+if (isTab.current) {const ctx = new AudioContext();const src = ctx.createMediaStreamSource(screenStream.current);diff --git a/src/pages/Recorder/Recorder.jsx b/src/pages/Recorder/Recorder.jsxindex f7acf1e..39b2833 100644--- a/src/pages/Recorder/Recorder.jsx+++ b/src/pages/Recorder/Recorder.jsx@@ -21,7 +21,10 @@ import { shouldAcquireMicAtStart } from "../utils/micAcquisitionPolicy";import { attachAudioContextWatchdog } from "../utils/audioContextWatchdog";import { IS_OFFSCREEN_HOST } from "../utils/recordingHost";import { sendSystemAudioGuidanceToast } from "../utils/systemAudioGuidance";-import { shouldUseDisplayMediaForScreen } from "../utils/screenCaptureMode";+import {+ shouldUseDisplayMediaForScreen,+ screenSurfaceSwitching,+} from "../utils/screenCaptureMode";import { acquireDisplayMediaWithFocusRetry } from "../utils/acquireDisplayMedia";import { chooseWriter } from "./recorderStorage/chooseWriter";import { chooseReader } from "./recorderStorage/chooseReader";@@ -3502,6 +3505,9 @@ const Recorder = () => {} else if (useDisplayMedia) {// macOS + Chrome 141+ screen path: getDisplayMedia for system audio.// Falls through to the shared mixing/recorder setup below.+ const { disableSurfaceSwitching } = await chrome.storage.local.get([+ "disableSurfaceSwitching",+ ]);const displayConstraints = {audio: data.systemAudio ? true : false,video: {@@ -3510,11 +3516,11 @@ const Recorder = () => {height: { ideal: height, max: height },displaySurface: "monitor",},- // systemAudio:"include" (default may hide the toggle);- // surfaceSwitching:"exclude" dodges crbug 344876285 (switch ends mac- // audio). Screen-only; these throw TypeError w/ preferCurrentTab.+ // systemAudio:"include" (default may hide the toggle). surfaceSwitching+ // keeps Chrome's "Share this tab instead" button. Screen-only; these+ // throw TypeError w/ preferCurrentTab.systemAudio: "include",- surfaceSwitching: "exclude",+ surfaceSwitching: screenSurfaceSwitching({ disableSurfaceSwitching }),selfBrowserSurface: "exclude",};debug("getDisplayMedia screen constraints", displayConstraints);diff --git a/src/pages/Recorder/webcodecs/WebCodecsRecorder.js b/src/pages/Recorder/webcodecs/WebCodecsRecorder.jsindex 580d36c..2a3631b 100644--- a/src/pages/Recorder/webcodecs/WebCodecsRecorder.js+++ b/src/pages/Recorder/webcodecs/WebCodecsRecorder.js@@ -11,6 +11,7 @@*/import { perfMark, perfSpan } from "../../utils/perfMarks";import { diagForward } from "../../utils/diagForward";+import { computeLetterboxRect } from "./letterbox";import {AAC_SUPPORTED_RATES,AVC_MAX_PIXELS,@@ -104,6 +105,7 @@ export class WebCodecsRecorder {this.resizeCanvas = null;this.resizeCtx = null;+ this._loggedLetterbox = false;this.justResumed = false;this.paused = false;@@ -2286,6 +2288,36 @@ export class WebCodecsRecorder {throw new Error("WebCodecsRecorder: No supported H.264 encoder");}+ // Geometry lives in letterbox.js; this just paints it.+ drawFrameToResizeCanvas(frame) {+ const tw = this.targetWidth;+ const th = this.targetHeight;+ const rect = computeLetterboxRect({+ sw: frame.codedWidth,+ sh: frame.codedHeight,+ tw,+ th,+ });++ if (rect.fills) {+ this.resizeCtx.drawImage(frame, 0, 0, tw, th);+ return;+ }++ if (!this._loggedLetterbox) {+ this._loggedLetterbox = true;+ this.log(+ `[WCR] surface aspect changed; letterboxing ${frame.codedWidth}x${frame.codedHeight} into ${tw}x${th}`,+ );+ }++ // A fitted draw doesn't cover every pixel; without this the previous surface+ // stays frozen in the bars around the new one.+ this.resizeCtx.fillStyle = "#000";+ this.resizeCtx.fillRect(0, 0, tw, th);+ this.resizeCtx.drawImage(frame, rect.x, rect.y, rect.w, rect.h);+ }+async readVideoLoop() {this.log("[WCR] video loop start");if (!this.videoReader || !this.videoEncoder) return;@@ -2431,13 +2463,7 @@ export class WebCodecsRecorder {ensureResizeCanvas();- this.resizeCtx.drawImage(- frame,- 0,- 0,- this.targetWidth,- this.targetHeight,- );+ this.drawFrameToResizeCanvas(frame);if (!this._videoStartUs) {this._videoStartUs = performance.now() * 1000;diff --git a/src/pages/Recorder/webcodecs/letterbox.js b/src/pages/Recorder/webcodecs/letterbox.jsnew file mode 100644index 0000000..25f8168--- /dev/null+++ b/src/pages/Recorder/webcodecs/letterbox.js@@ -0,0 +1,25 @@+// Fit + pad a source frame onto the encoder's fixed-size canvas so a+// mid-recording surface switch with a different aspect gets letterboxed, not+// stretched. Pure; unit-tested in tests/unit/.+export function computeLetterboxRect({ sw, sh, tw, th }) {+ if (!(sw > 0) || !(sh > 0) || !(tw > 0) || !(th > 0)) {+ return { x: 0, y: 0, w: tw, h: th, fills: true };+ }++ // Equal aspect (cross-multiplied) fills the canvas, so the caller can skip clearing.+ if (sw * th === sh * tw) {+ return { x: 0, y: 0, w: tw, h: th, fills: true };+ }++ const scale = Math.min(tw / sw, th / sh);+ const w = Math.max(1, Math.round(sw * scale));+ const h = Math.max(1, Math.round(sh * scale));++ return {+ x: Math.round((tw - w) / 2),+ y: Math.round((th - h) / 2),+ w,+ h,+ fills: false,+ };+}diff --git a/src/pages/utils/screenCaptureMode.js b/src/pages/utils/screenCaptureMode.jsindex 442c17f..f7aefa8 100644--- a/src/pages/utils/screenCaptureMode.js+++ b/src/pages/utils/screenCaptureMode.js@@ -38,3 +38,11 @@ export function shouldUseDisplayMediaForScreen(settings = {}) {disabled: settings.macSystemAudioCapture === false,});}++// Chrome's "Share this tab instead" button; on by default, with+// disableSurfaceSwitching as a storage kill-switch. Not gated on mac/systemAudio+// (crbug 344876285 is Won't Fix, and sysTrack.onended keeps the take alive).+// Region/crop never reaches here (cropTo is bound to the original tab).+export function screenSurfaceSwitching(settings = {}) {+ return settings.disableSurfaceSwitching === true ? "exclude" : "include";+}