-
Notifications
You must be signed in to change notification settings - Fork 2
feat: browser focus mode, webview migration, session composer store #255
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
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
06a4ca5
feat: browser focus mode, webview migration, session composer store
zvadaadam 1790dd6
fix: default webview devtools mode to detached
zvadaadam 2e4aaeb
review: address coderabbit round 1
zvadaadam 8ddbee5
review: address coderabbit round 2
zvadaadam 8e68594
review: address coderabbit round 3 (docs accuracy)
zvadaadam 8772ce0
review: address coderabbit round 4
zvadaadam 0c42d88
feat: dock browser devtools inside panel via setDevToolsWebContents
zvadaadam 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| /** | ||
| * Main-process helpers for the <webview>-based browser path. | ||
| * | ||
| * 1. CDP viewport emulation (requires debugger attach — cannot be done | ||
| * from executeJavaScript, which runs in the guest page context). | ||
| * 2. DevTools open/close. Routing through `webContents` pairs our toolbar | ||
| * toggle with an explicit close. Guest DevTools always open detached — | ||
| * docked modes (`bottom`/`right`) silently fail because the guest has | ||
| * no BrowserWindow to dock into. | ||
| * | ||
| * Both identify the target by `webContentsId`, which the renderer gets from | ||
| * `webview.getWebContentsId()` after the guest page attaches. | ||
| */ | ||
|
|
||
| import { ipcMain, webContents } from "electron"; | ||
|
|
||
| const emulatedIds = new Set<number>(); | ||
|
|
||
| export function registerBrowserEmulationHandlers(): void { | ||
| ipcMain.handle( | ||
| "browser_webview_emulation_set", | ||
| async ( | ||
| _e, | ||
| { | ||
| webContentsId, | ||
| width, | ||
| height, | ||
| deviceScaleFactor, | ||
| mobile, | ||
| scale, | ||
| }: { | ||
| webContentsId: number; | ||
| width: number; | ||
| height: number; | ||
| deviceScaleFactor: number; | ||
| mobile: boolean; | ||
| scale?: number; | ||
| } | ||
| ): Promise<{ success: boolean; error?: string }> => { | ||
| const wc = webContents.fromId(webContentsId); | ||
| if (!wc || wc.isDestroyed()) return { success: false, error: "webContents not found" }; | ||
|
|
||
| try { | ||
| if (!wc.debugger.isAttached()) wc.debugger.attach("1.3"); | ||
|
|
||
| // Always apply device-metrics override so the page reflows for the | ||
| // emulated device (mobile UA + breakpoints kick in from the `mobile` | ||
| // flag + width). Separately, a sub-unity `scale` shrinks the rendered | ||
| // output so oversized viewports (Desktop 1920×1080 on a narrow panel) | ||
| // still fit — that's exactly what webContents.setZoomFactor does. | ||
| await wc.debugger.sendCommand("Emulation.setDeviceMetricsOverride", { | ||
| width, | ||
| height, | ||
| deviceScaleFactor, | ||
| mobile, | ||
| }); | ||
| wc.setZoomFactor(scale !== undefined && scale < 1 ? scale : 1); | ||
|
|
||
| await wc.debugger.sendCommand("Emulation.setTouchEmulationEnabled", { | ||
| enabled: mobile, | ||
| ...(mobile ? { maxTouchPoints: 5 } : {}), | ||
| }); | ||
|
|
||
| emulatedIds.add(webContentsId); | ||
| return { success: true }; | ||
| } catch (err) { | ||
| return { success: false, error: String(err) }; | ||
| } | ||
| } | ||
| ); | ||
|
|
||
| ipcMain.handle( | ||
| "browser_webview_emulation_clear", | ||
| async ( | ||
| _e, | ||
| { webContentsId }: { webContentsId: number } | ||
| ): Promise<{ success: boolean; error?: string }> => { | ||
| const wc = webContents.fromId(webContentsId); | ||
| if (!wc || wc.isDestroyed()) return { success: false, error: "webContents not found" }; | ||
|
|
||
| try { | ||
| if (wc.debugger.isAttached()) { | ||
| await wc.debugger.sendCommand("Emulation.clearDeviceMetricsOverride", {}); | ||
| await wc.debugger.sendCommand("Emulation.setTouchEmulationEnabled", { enabled: false }); | ||
| // Detach the debugger so Chromium fully releases emulation state and | ||
| // re-runs layout against the webview element's real dimensions. Just | ||
| // calling clearDeviceMetricsOverride leaves an active CDP session | ||
| // that can retain stale viewport state — the page stays laid-out at | ||
| // the previous mobile dims until something else (navigation, zoom | ||
| // change) invalidates layout. Detaching is the cleanest signal. | ||
| // Next setEmulation call re-attaches (it checks isAttached()). | ||
| wc.debugger.detach(); | ||
| } | ||
| wc.setZoomFactor(1); | ||
| emulatedIds.delete(webContentsId); | ||
| return { success: true }; | ||
| } catch (err) { | ||
| return { success: false, error: String(err) }; | ||
| } | ||
| } | ||
| ); | ||
|
|
||
| ipcMain.handle( | ||
| "browser_webview_devtools_open", | ||
| ( | ||
| _e, | ||
| { | ||
| webContentsId, | ||
| mode = "detach", | ||
| }: { webContentsId: number; mode?: "right" | "bottom" | "undocked" | "detach" } | ||
| ): { success: boolean; error?: string } => { | ||
| const wc = webContents.fromId(webContentsId); | ||
| if (!wc || wc.isDestroyed()) return { success: false, error: "webContents not found" }; | ||
| try { | ||
| wc.openDevTools({ mode }); | ||
| return { success: true }; | ||
| } catch (err) { | ||
| return { success: false, error: String(err) }; | ||
| } | ||
| } | ||
| ); | ||
|
|
||
| ipcMain.handle( | ||
| "browser_webview_devtools_close", | ||
| (_e, { webContentsId }: { webContentsId: number }): { success: boolean; error?: string } => { | ||
| const wc = webContents.fromId(webContentsId); | ||
| if (!wc || wc.isDestroyed()) return { success: false, error: "webContents not found" }; | ||
| try { | ||
| wc.closeDevTools(); | ||
| return { success: true }; | ||
| } catch (err) { | ||
| return { success: false, error: String(err) }; | ||
| } | ||
| } | ||
| ); | ||
| } | ||
Oops, something went wrong.
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.