@@ -1305,10 +1305,6 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
13051305 confirmedNavigation = false ,
13061306 ) {
13071307 if ( wc . isDestroyed ( ) ) return ;
1308- const zoomFactor = yield * attempt (
1309- { operation : "syncWebContentsState.getZoomFactor" , tabId, webContentsId : wc . id } ,
1310- ( ) => wc . getZoomFactor ( ) ,
1311- ) . pipe ( Effect . option ) ;
13121308 const computedNavStatus = computeNavStatus ( wc ) ;
13131309 const canGoBack = wc . navigationHistory . canGoBack ( ) ;
13141310 const canGoForward = wc . navigationHistory . canGoForward ( ) ;
@@ -1338,7 +1334,9 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
13381334 navStatus,
13391335 canGoBack,
13401336 canGoForward,
1341- ...( Option . isSome ( zoomFactor ) ? { zoomFactor : zoomFactor . value } : { } ) ,
1337+ // zoomFactor is deliberately not read back from the guest: Chromium
1338+ // reports the level it inherited from the app window, so mirroring it
1339+ // would turn an app zoom into the preview's own zoom.
13421340 updatedAt,
13431341 } ;
13441342 return [
@@ -1716,11 +1714,10 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
17161714 const annotationTheme = yield * Ref . get ( annotationThemeRef ) ;
17171715 const currentAttachment = attached . get ( webContentsId ) ;
17181716 if ( tab . webContentsId === webContentsId && currentAttachment ?. webContents === wc ) {
1719- const zoomFactor = yield * attempt (
1720- { operation : "registerWebview.getZoomFactor" , tabId, webContentsId } ,
1721- ( ) => wc . getZoomFactor ( ) ,
1717+ yield * attempt ( { operation : "registerWebview.restoreZoomFactor" , tabId, webContentsId } , ( ) =>
1718+ wc . setZoomFactor ( tab . zoomFactor ) ,
17221719 ) ;
1723- yield * update ( tabId , { zoomFactor } ) ;
1720+ yield * update ( tabId , { zoomFactor : tab . zoomFactor } ) ;
17241721 yield * attempt ( { operation : "registerWebview.sendTheme" , tabId, webContentsId } , ( ) =>
17251722 wc . send ( ANNOTATION_THEME_CHANNEL , annotationTheme ) ,
17261723 ) ;
@@ -1749,18 +1746,16 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
17491746 ) {
17501747 return yield * new PreviewTabNotFoundError ( { tabId } ) ;
17511748 }
1752- const zoomFactor =
1753- replacedWebContentsId !== null
1754- ? yield * attempt (
1755- { operation : "registerWebview.restoreZoomFactor" , tabId, webContentsId } ,
1756- ( ) => {
1757- wc . setZoomFactor ( currentTab . zoomFactor ) ;
1758- return currentTab . zoomFactor ;
1759- } ,
1760- )
1761- : yield * attempt ( { operation : "registerWebview.getZoomFactor" , tabId, webContentsId } , ( ) =>
1762- wc . getZoomFactor ( ) ,
1763- ) ;
1749+ // Always assert the tab's own zoom rather than reading the guest's: a guest
1750+ // attaching while the app UI is zoomed starts at the embedder's inherited
1751+ // zoom level, which is not the preview's zoom.
1752+ const zoomFactor = yield * attempt (
1753+ { operation : "registerWebview.restoreZoomFactor" , tabId, webContentsId } ,
1754+ ( ) => {
1755+ wc . setZoomFactor ( currentTab . zoomFactor ) ;
1756+ return currentTab . zoomFactor ;
1757+ } ,
1758+ ) ;
17641759 yield * attachListeners ( tabId , wc ) ;
17651760 const registeredAt = yield * currentIso ;
17661761 const registration = yield * SynchronizedRef . modifyEffect ( tabsRef , ( tabs ) =>
@@ -2099,6 +2094,28 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
20992094 ) ;
21002095 } ) ;
21012096
2097+ /**
2098+ * Chromium hands every guest `<webview>` the embedder's zoom level, so zooming
2099+ * the app UI drags the previewed page along with it. The preview browser owns
2100+ * its own zoom factor, so re-assert it on each attached guest whenever the main
2101+ * window's zoom changes (see DesktopWindow.zoomMain).
2102+ */
2103+ const reapplyZoom = Effect . fn ( "PreviewManager.reapplyZoom" ) ( function * ( ) {
2104+ const tabs = yield * SynchronizedRef . get ( tabsRef ) ;
2105+ yield * Effect . forEach (
2106+ tabs . values ( ) ,
2107+ ( tab ) => {
2108+ if ( tab . webContentsId === null ) return Effect . void ;
2109+ const wc = webContents . fromId ( tab . webContentsId ) ;
2110+ if ( ! wc || wc . isDestroyed ( ) ) return Effect . void ;
2111+ return attempt ( { operation : "reapplyZoom" , tabId : tab . tabId , webContentsId : wc . id } , ( ) =>
2112+ wc . setZoomFactor ( tab . zoomFactor ) ,
2113+ ) . pipe ( Effect . ignore ) ;
2114+ } ,
2115+ { discard : true } ,
2116+ ) ;
2117+ } ) ;
2118+
21022119 const applyZoom = Effect . fn ( "PreviewManager.applyZoom" ) ( function * (
21032120 tabId : string ,
21042121 transform : ( current : number ) => number ,
@@ -3476,6 +3493,7 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
34763493 openPictureInPicture,
34773494 openDevTools,
34783495 pickElement,
3496+ reapplyZoom,
34793497 refresh,
34803498 registerWebview,
34813499 resetZoom : ( tabId : string ) => applyZoom ( tabId , ( ) => DEFAULT_ZOOM_FACTOR ) ,
@@ -3774,6 +3792,9 @@ export class PreviewManager extends Context.Service<
37743792 readonly zoomIn : ( tabId : string ) => Effect . Effect < void , PreviewManagerError > ;
37753793 readonly zoomOut : ( tabId : string ) => Effect . Effect < void , PreviewManagerError > ;
37763794 readonly resetZoom : ( tabId : string ) => Effect . Effect < void , PreviewManagerError > ;
3795+ // Re-applies every attached guest's own zoom factor, undoing the zoom level
3796+ // Chromium inherits from the embedder when the app UI zooms.
3797+ readonly reapplyZoom : ( ) => Effect . Effect < void > ;
37773798 readonly hardReload : ( tabId : string ) => Effect . Effect < void , PreviewManagerError > ;
37783799 readonly setColorScheme : (
37793800 tabId : string ,
@@ -3874,6 +3895,7 @@ export const make = Effect.gen(function* PreviewManagerMake() {
38743895 zoomIn : operations . zoomIn ,
38753896 zoomOut : operations . zoomOut ,
38763897 resetZoom : operations . resetZoom ,
3898+ reapplyZoom : operations . reapplyZoom ,
38773899 hardReload : operations . hardReload ,
38783900 setColorScheme : operations . setColorScheme ,
38793901 openDevTools : operations . openDevTools ,
0 commit comments