@@ -52,13 +52,21 @@ export function find(target) {
52
52
}
53
53
54
54
export function select ( type , rect ) {
55
+ const tabConnectionFailure = ( ) => {
56
+ ModalState . showAlert ( {
57
+ title : "Can't connect to tab" ,
58
+ description : "Make sure the tab begins with `http://`, or try to refresh the tab." ,
59
+ confirmLabel : "Close"
60
+ } ) ;
61
+ UiState . setSelectingTarget ( false ) ;
62
+ } ;
55
63
UiState . setSelectingTarget ( ! UiState . isSelectingTarget ) ;
56
64
if ( ! UiState . isSelectingTarget ) {
57
65
browser . tabs . query ( {
58
66
active : true ,
59
67
windowId : window . contentWindowId
60
68
} ) . then ( function ( tabs ) {
61
- browser . tabs . sendMessage ( tabs [ 0 ] . id , { selectMode : true , selecting : false } ) ;
69
+ browser . tabs . sendMessage ( tabs [ 0 ] . id , { selectMode : true , selecting : false } ) . catch ( tabConnectionFailure ) ;
62
70
} ) . catch ( function ( reason ) {
63
71
console . log ( reason ) ;
64
72
} ) ;
@@ -73,9 +81,9 @@ export function select(type, rect) {
73
81
UiState . setSelectingTarget ( false ) ;
74
82
} else {
75
83
if ( type === TargetTypes . LOCATOR ) {
76
- browser . tabs . sendMessage ( tabs [ 0 ] . id , { selectMode : true , selecting : true , element : true } ) ;
84
+ browser . tabs . sendMessage ( tabs [ 0 ] . id , { selectMode : true , selecting : true , element : true } ) . catch ( tabConnectionFailure ) ;
77
85
} else if ( type === TargetTypes . REGION ) {
78
- browser . tabs . sendMessage ( tabs [ 0 ] . id , { selectMode : true , selecting : true , region : true , rect : new Region ( rect ) . toJS ( ) } ) ;
86
+ browser . tabs . sendMessage ( tabs [ 0 ] . id , { selectMode : true , selecting : true , region : true , rect : new Region ( rect ) . toJS ( ) } ) . catch ( tabConnectionFailure ) ;
79
87
}
80
88
}
81
89
} ) ;
0 commit comments