Repository navigation
fix(desktop): capture browser tabs while macOS is locked #41212
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
Open
JayHopsHQ
wants to merge
2
commits into
pingdotgg:main
Choose a base branch
from
JayHopsHQ:fix/macos-locked-capture-rebased
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+130
−1
Open
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { describe, expect, it } from "vite-plus/test"; | ||
|
|
||
| import { captureGuestPage } from "./GuestCapture.ts"; | ||
|
|
||
| const nativePage = () => | ||
| ({ | ||
| capturePage: async () => ({ | ||
| toPNG: () => Buffer.from("native png"), | ||
| toJPEG: (quality: number) => Buffer.from(`native jpeg ${quality}`), | ||
| }), | ||
| }) as unknown as Electron.WebContents; | ||
|
|
||
| const unavailableDebugger = { | ||
| sendCommand: async () => { | ||
| throw new Error("CDP capture is blocked"); | ||
| }, | ||
| } as unknown as Electron.Debugger; | ||
|
|
||
| describe("captureGuestPage", () => { | ||
| it("returns a viewport frame when CDP capture is unavailable", async () => { | ||
| const result = await captureGuestPage(nativePage(), unavailableDebugger, {}); | ||
| expect(result).toEqual({ data: Buffer.from("native png").toString("base64") }); | ||
| }); | ||
|
|
||
| it("retains JPEG quality for remote viewer still frames", async () => { | ||
| const result = await captureGuestPage(nativePage(), unavailableDebugger, { | ||
| format: "jpeg", | ||
| quality: 65, | ||
| }); | ||
| expect(result).toEqual({ data: Buffer.from("native jpeg 65").toString("base64") }); | ||
| }); | ||
|
|
||
| it("preserves CDP capture options that native viewport capture cannot represent", async () => { | ||
| const params = { format: "png", clip: { x: 10, y: 20, width: 30, height: 40, scale: 2 } }; | ||
| const debuggee = { | ||
| sendCommand: async (method: string, received: unknown) => ({ method, received }), | ||
| } as unknown as Electron.Debugger; | ||
| expect(await captureGuestPage(nativePage(), debuggee, params)).toEqual({ | ||
| method: "Page.captureScreenshot", | ||
| received: params, | ||
| }); | ||
| }); | ||
| }); |
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 |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /** Native capture supplies unchanged frames when an occluded guest's CDP capture stops. */ | ||
| export const captureGuestPage = async ( | ||
| webContents: Electron.WebContents, | ||
| debuggee: Electron.Debugger, | ||
| params: Record<string, unknown>, | ||
| ): Promise<unknown> => { | ||
| const format = params["format"] ?? "png"; | ||
| if ( | ||
| Object.keys(params).some( | ||
| (key) => | ||
| !["format", "quality", "optimizeForSpeed", "captureBeyondViewport", "fromSurface"].includes( | ||
| key, | ||
| ), | ||
| ) || | ||
| params["clip"] !== undefined || | ||
| params["captureBeyondViewport"] === true || | ||
| params["fromSurface"] === false || | ||
| (format !== "png" && format !== "jpeg") | ||
| ) { | ||
| return debuggee.sendCommand("Page.captureScreenshot", params); | ||
| } | ||
| const image = await webContents.capturePage(undefined, { stayHidden: true }); | ||
| const data = | ||
| format === "jpeg" | ||
| ? image.toJPEG(typeof params["quality"] === "number" ? params["quality"] : 80) | ||
| : image.toPNG(); | ||
| return { data: data.toString("base64") }; | ||
| }; | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Native screenshots can return a frame that predates a just-completed DOM change.
The PNG and JPEG path calls
webContents.capturePage, which callsCopyFromSurfacedirectly. This path does not request a redraw first. A screenshot requested after a DOM change and before the next compositor frame can therefore return the previous frame. Require the native capture to reflect DOM changes completed before the request. Choose how to meet this requirement: force a frame update before capture, or route such requests through the CDP path. The evidence does not select one option.