@@ -138,9 +138,10 @@ export default class PlaybackController extends BaseController {
138138 const browserInfo = this . session . store . get ( 'browserInfo' )
139139 const allowMultiplePlaybacks =
140140 ( await this . isParallel ( ) ) && this . testQueue . length
141- const makeNewPlayback = ! this . playbacks . length || allowMultiplePlaybacks
141+ const makeNewPlayback = ! this . playbacks . length || allowMultiplePlaybacks
142+ let playback : Playback
142143 if ( makeNewPlayback ) {
143- const playback = new Playback ( {
144+ playback = new Playback ( {
144145 baseUrl : this . session . projects . project . url ,
145146 executor : await this . session . driver . build ( {
146147 browser : browserInfo . browser ,
@@ -171,28 +172,24 @@ export default class PlaybackController extends BaseController {
171172 } else {
172173 await playback . executor . driver . switchTo ( ) . newWindow ( 'window' )
173174 }
174- const state = await this . session . state . get ( )
175- const currentCommand = getActiveCommand ( state )
176- const url =
177- currentCommand . command === 'open'
178- ? new URL ( currentCommand . target as string , state . project . url ) . href
179- : state . project . url
180- playback . executor . doOpen ( url )
181- return playback
175+ } else {
176+ playback = this . playbacks [ 0 ]
177+ await this . claimPlaybackWindow ( playback )
182178 }
183- return this . playbacks [ 0 ]
179+ return playback
184180 }
185181
186182 async claimPlaybackWindow ( playback : Playback ) {
187183 const executor = playback . executor
188184 const driver = executor . driver
189- const handle = await driver . getWindowHandle ( )
190- const existingWindow = await this . session . windows . getPlaybackWindowByHandle (
191- handle
192- )
193- if ( existingWindow && existingWindow . isVisible ( ) ) {
194- return
195- }
185+ try {
186+ const handle = await driver . getWindowHandle ( )
187+ const existingWindow =
188+ await this . session . windows . getPlaybackWindowByHandle ( handle )
189+ if ( existingWindow && existingWindow . isVisible ( ) ) {
190+ return
191+ }
192+ } catch ( windowDoesNotExist ) { }
196193 let success = false
197194 const UUID = randomUUID ( )
198195 const window = await this . session . windows . openPlaybackWindow ( {
@@ -220,6 +217,13 @@ export default class PlaybackController extends BaseController {
220217 if ( ! success ) {
221218 throw new Error ( 'Failed to switch to playback window' )
222219 }
220+ const state = await this . session . state . get ( )
221+ const currentCommand = getActiveCommand ( state )
222+ const url =
223+ currentCommand . command === 'open'
224+ ? new URL ( currentCommand . target as string , state . project . url ) . href
225+ : state . project . url
226+ playback . executor . doOpen ( url )
223227 }
224228
225229 async play ( testID : string , playRange = PlaybackController . defaultPlayRange ) {
0 commit comments