1- import * as React from 'react' ;
2- import { observer } from 'mobx-react' ;
3- import { observable } from 'mobx' ;
41import dedent from 'dedent' ;
52
63import { Interceptor } from '../../../model/interception/interceptors' ;
74
8- @observer
9- class ExistingBrowserConfig extends React . Component < {
5+ export async function onActivateExistingBrowser (
106 interceptor : Interceptor ,
117 activateInterceptor : (
128 options : { closeConfirmed ?: true } ,
139 shouldTrackEvent ?: false
1410 ) => Promise < void > ,
1511 reportStarted : ( ) => void ,
1612 reportSuccess : ( options ?: { showRequests ?: boolean } ) => void ,
17- closeSelf : ( ) => void
18- } > {
19-
20- async componentDidMount ( ) {
21- const { activateInterceptor, reportStarted, reportSuccess, closeSelf } = this . props ;
22- closeSelf ( ) ; // We immediately unmount, but continue activating:
23-
24- try {
25- // Try to activate, assuming the browser isn't currently open:
26- await activateInterceptor ( { } , false ) ;
27-
28- // Only it runs without confirmation does this count as an activation
29- reportStarted ( ) ;
30- } catch ( error : any ) {
31- if ( ! error . metadata || error . metadata . closeConfirmRequired !== true ) {
32- // This is a real error, not a confirmation requirement.
33-
34- reportStarted ( ) ; // Track that this started, before it fails
35- throw error ;
36- }
37-
38- // If the browser is open, confirm that we can kill & restart it first:
39- const confirmed = confirm ( dedent `
40- Your browser is currently open, and needs to be
41- restarted to enable interception. Restart it now?
42- ` . replace ( '\n' , ' ' ) ) ;
43-
44- // If cancelled, we silently do nothing
45- if ( ! confirmed ) return ;
46-
47- reportStarted ( ) ;
48- await activateInterceptor ( { closeConfirmed : true } ) ;
13+ ) {
14+ try {
15+ // Try to activate, assuming the browser isn't currently open:
16+ await activateInterceptor ( { } , false ) ;
17+
18+ // Only it runs without confirmation does this count as an activation
19+ reportStarted ( ) ;
20+ } catch ( error : any ) {
21+ if ( ! error . metadata || error . metadata . closeConfirmRequired !== true ) {
22+ // This is a real error, not a confirmation requirement.
23+
24+ reportStarted ( ) ; // Track that this started, before it fails
25+ throw error ;
4926 }
5027
51- reportSuccess ( ) ;
52- }
28+ // If the browser is open, confirm that we can kill & restart it first:
29+ const confirmed = confirm ( dedent `
30+ Your browser is currently open, and needs to be
31+ restarted to enable interception. Restart it now?
32+ ` . replace ( '\n' , ' ' ) ) ;
5333
54- render ( ) {
55- return null ; // This never actually displays - we just mount, confirm, and close
56- }
34+ // If cancelled, we silently do nothing
35+ if ( ! confirmed ) return ;
5736
58- }
37+ reportStarted ( ) ;
38+ await activateInterceptor ( { closeConfirmed : true } ) ;
39+ }
5940
60- export const ExistingBrowserCustomUi = {
61- columnWidth : 1 ,
62- rowHeight : 1 ,
63- configComponent : ExistingBrowserConfig
64- } ;
41+ reportSuccess ( ) ;
42+ }
0 commit comments