1
- import * as React from 'react' ;
2
- import { observer } from 'mobx-react' ;
3
- import { observable } from 'mobx' ;
4
1
import dedent from 'dedent' ;
5
2
6
3
import { Interceptor } from '../../../model/interception/interceptors' ;
7
4
8
- @observer
9
- class ExistingBrowserConfig extends React . Component < {
5
+ export async function onActivateExistingBrowser (
10
6
interceptor : Interceptor ,
11
7
activateInterceptor : (
12
8
options : { closeConfirmed ?: true } ,
13
9
shouldTrackEvent ?: false
14
10
) => Promise < void > ,
15
11
reportStarted : ( ) => void ,
16
12
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 ;
49
26
}
50
27
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' , ' ' ) ) ;
53
33
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 ;
57
36
58
- }
37
+ reportStarted ( ) ;
38
+ await activateInterceptor ( { closeConfirmed : true } ) ;
39
+ }
59
40
60
- export const ExistingBrowserCustomUi = {
61
- columnWidth : 1 ,
62
- rowHeight : 1 ,
63
- configComponent : ExistingBrowserConfig
64
- } ;
41
+ reportSuccess ( ) ;
42
+ }
0 commit comments