599599 .player-wrap {
600600 min-height : 0 ;
601601 overflow : auto;
602- padding : 16px ;
603602 }
604603
605604 # player {
605+ min-height : 0 ;
606606 width : 100% ;
607- min-height : 320px ;
607+ }
608+
609+ # player .rr-player {
610+ background : var (--surface ) !important ;
611+ border-radius : 0 !important ;
612+ box-shadow : none !important ;
613+ margin : 0 !important ;
614+ width : 100% !important ;
615+ }
616+
617+ # player .rr-player__frame ,
618+ # player .replayer-wrapper {
619+ border-radius : 0 !important ;
620+ box-shadow : none !important ;
608621 }
609622
610623 .empty ,
@@ -1178,6 +1191,8 @@ <h2>Session context</h2>
11781191 inspectorCollapsed : false ,
11791192 } ;
11801193
1194+ const playerControllerHeight = 80 ;
1195+
11811196 const modes = {
11821197 sessions : { label : "Recent sessions" } ,
11831198 events : { label : "Analytics events" } ,
@@ -1397,6 +1412,7 @@ <h2>Session context</h2>
13971412 state . playerAnchorMs = 0 ;
13981413 state . playerWidth = 0 ;
13991414 state . playerHeight = 0 ;
1415+ els . player . style . minHeight = "" ;
14001416 els . player . innerHTML = "" ;
14011417 const wrap = document . createElement ( "div" ) ;
14021418 wrap . className = kind === "error" ? "error" : "empty" ;
@@ -1922,6 +1938,7 @@ <h2>Session context</h2>
19221938 const { width, height } = playerDimensions ( ) ;
19231939 state . playerWidth = width ;
19241940 state . playerHeight = height ;
1941+ els . player . style . minHeight = `${ height + playerControllerHeight } px` ;
19251942 state . player = new rrwebPlayer ( {
19261943 target : els . player ,
19271944 props : {
@@ -1932,6 +1949,7 @@ <h2>Session context</h2>
19321949 showController : true ,
19331950 } ,
19341951 } ) ;
1952+ fitReplayViewport ( ) ;
19351953 seekPlayer ( state . playerAnchorMs ) ;
19361954 }
19371955
@@ -1945,11 +1963,42 @@ <h2>Session context</h2>
19451963
19461964 function playerDimensions ( ) {
19471965 const wrap = els . player . parentElement ;
1948- const width = Math . max ( 640 , Math . floor ( ( wrap ?. clientWidth || 0 ) - 32 ) ) ;
1949- const height = Math . max ( 360 , Math . round ( width * 0.5625 ) ) ;
1966+ const width = Math . max ( 320 , Math . floor ( wrap ?. clientWidth || els . player . clientWidth || 960 ) ) ;
1967+ const availableHeight = Math . floor ( wrap ?. clientHeight || els . player . clientHeight || 0 ) ;
1968+ const aspectRatio = playerAspectRatio ( ) ;
1969+ const fullWidthHeight = Math . round ( width / aspectRatio ) ;
1970+ const constrainedHeight =
1971+ availableHeight > playerControllerHeight + 240
1972+ ? Math . min ( fullWidthHeight , availableHeight - playerControllerHeight )
1973+ : fullWidthHeight ;
1974+ const height = Math . max ( 240 , constrainedHeight ) ;
19501975 return { width, height } ;
19511976 }
19521977
1978+ function playerAspectRatio ( ) {
1979+ const meta = state . playerEvents . find (
1980+ ( event ) => event ?. type === 4 && event ?. data ?. width > 0 && event ?. data ?. height > 0 ,
1981+ ) ;
1982+ if ( ! meta ) return 16 / 9 ;
1983+ return meta . data . width / meta . data . height ;
1984+ }
1985+
1986+ function fitReplayViewport ( ) {
1987+ const applyFit = ( ) => {
1988+ const frame = els . player . querySelector ( ".rr-player__frame" ) ;
1989+ const wrapper = els . player . querySelector ( ".replayer-wrapper" ) ;
1990+ if ( ! frame || ! wrapper ) return ;
1991+ const naturalWidth = wrapper . offsetWidth ;
1992+ const naturalHeight = wrapper . offsetHeight ;
1993+ if ( ! naturalWidth || ! naturalHeight ) return ;
1994+ const scale = Math . min ( frame . clientWidth / naturalWidth , frame . clientHeight / naturalHeight ) ;
1995+ wrapper . style . transform = `scale(${ scale } ) translate(-50%, -50%)` ;
1996+ } ;
1997+ window . requestAnimationFrame ( applyFit ) ;
1998+ window . setTimeout ( applyFit , 0 ) ;
1999+ window . setTimeout ( applyFit , 180 ) ;
2000+ }
2001+
19532002 function resizePlayer ( ) {
19542003 if ( ! state . playerEvents . length || typeof rrwebPlayer === "undefined" ) return ;
19552004 const { width, height } = playerDimensions ( ) ;
@@ -1968,14 +2017,15 @@ <h2>Session context</h2>
19682017 try {
19692018 if ( state . player ?. goto ) {
19702019 state . player . goto ( offset , false ) ;
1971- return ;
1972- }
1973- const replayer = state . player ?. getReplayer ?. ( ) ;
1974- if ( replayer ?. play && replayer ?. pause ) {
1975- replayer . play ( offset ) ;
1976- window . setTimeout ( ( ) => replayer . pause ( ) , 40 ) ;
2020+ } else if ( state . player ?. getReplayer ) {
2021+ const replayer = state . player . getReplayer ( ) ;
2022+ if ( replayer ?. play && replayer ?. pause ) {
2023+ replayer . play ( offset ) ;
2024+ window . setTimeout ( ( ) => replayer . pause ( ) , 40 ) ;
2025+ }
19772026 }
19782027 } catch ( _ ) { }
2028+ fitReplayViewport ( ) ;
19792029 } , 100 ) ;
19802030 }
19812031
0 commit comments