@@ -850,11 +850,11 @@ export class App extends Protocol<AppRequest, AppNotification, AppResult> {
850850 * Apps can manually report size changes to help the host adjust the iframe.
851851 * If `autoResize` is enabled (default), this is called automatically.
852852 *
853- * @param params - New height in pixels
853+ * @param params - New width and/or height in pixels
854854 *
855855 * @example Manually notify host of size change
856856 * ```typescript
857- * app.sendSizeChanged({ height: 600 });
857+ * app.sendSizeChanged({ width: 400, height: 600 });
858858 * ```
859859 *
860860 * @returns Promise that resolves when the notification is sent
@@ -895,6 +895,7 @@ export class App extends Protocol<AppRequest, AppNotification, AppResult> {
895895 */
896896 setupSizeChangedNotifications ( ) {
897897 let scheduled = false ;
898+ let lastWidth = 0 ;
898899 let lastHeight = 0 ;
899900
900901 const sendBodySizeChanged = ( ) => {
@@ -909,8 +910,6 @@ export class App extends Protocol<AppRequest, AppNotification, AppResult> {
909910 // Measure actual content size by temporarily setting html to fit-content.
910911 // This shrinks html to fit body (including body margins), giving us the
911912 // true minimum size needed by the content.
912- // Note: We must set both width and height to fit-content for accurate
913- // measurement, as setting only height can cause incorrect layout calculation.
914913 const originalWidth = html . style . width ;
915914 const originalHeight = html . style . height ;
916915 html . style . width = "fit-content" ;
@@ -919,12 +918,18 @@ export class App extends Protocol<AppRequest, AppNotification, AppResult> {
919918 html . style . width = originalWidth ;
920919 html . style . height = originalHeight ;
921920
921+ // Compensate for scrollbar width on Linux/Windows where scrollbars consume space.
922+ // On systems with overlay scrollbars (macOS), this will be 0.
923+ const scrollbarWidth = window . innerWidth - html . clientWidth ;
924+
925+ const width = Math . ceil ( rect . width + scrollbarWidth ) ;
922926 const height = Math . ceil ( rect . height ) ;
923927
924- // Only send if height actually changed (prevents feedback loops from style changes)
925- if ( height !== lastHeight ) {
928+ // Only send if size actually changed (prevents feedback loops from style changes)
929+ if ( width !== lastWidth || height !== lastHeight ) {
930+ lastWidth = width ;
926931 lastHeight = height ;
927- this . sendSizeChanged ( { height } ) ;
932+ this . sendSizeChanged ( { width , height } ) ;
928933 }
929934 } ) ;
930935 } ;
0 commit comments