@@ -53,8 +53,8 @@ export default class Tab extends Component<TabProps, TabState> {
53
53
return { hasError : true , theError : error } ;
54
54
}
55
55
56
- constructor ( props ) {
57
- super ( props ) ;
56
+ constructor ( properties ) {
57
+ super ( properties ) ;
58
58
this . state = {
59
59
browserState : {
60
60
canGoBack : false ,
@@ -82,14 +82,14 @@ export default class Tab extends Component<TabProps, TabState> {
82
82
}
83
83
} ;
84
84
85
- buildMenu = webview => {
85
+ buildMenu = ( webview ) => {
86
86
if ( ! webview . getWebContents ) return ; // 'not now, as you're running jest;
87
87
const { addTab, windowId } = this . props ;
88
88
// require here to avoid jest/electron remote issues
89
89
const contextMenu = require ( 'electron-context-menu' ) ;
90
90
contextMenu ( {
91
91
window : webview ,
92
- append : params => [
92
+ append : ( params ) => [
93
93
{
94
94
label : 'Open Link in New Tab.' ,
95
95
visible : params . linkURL . length > 0 ,
@@ -176,21 +176,21 @@ export default class Tab extends Component<TabProps, TabState> {
176
176
} ) ;
177
177
}
178
178
179
- componentWillReceiveProps ( nextProps ) {
180
- if ( JSON . stringify ( nextProps ) === JSON . stringify ( this . props ) ) return ;
179
+ componentWillReceiveProps ( nextProperties ) {
180
+ if ( JSON . stringify ( nextProperties ) === JSON . stringify ( this . props ) ) return ;
181
181
if ( ! this . state . browserState . mountedAndReady ) return ;
182
182
const {
183
183
focusWebview,
184
184
isActiveTab,
185
185
url,
186
186
updateTab,
187
187
index,
188
- shouldToggleDevTools ,
188
+ shouldToggleDevelopmentTools ,
189
189
shouldReload
190
190
} = this . props ;
191
191
const { webview } = this ;
192
192
logger . info ( 'Tab: did receive updated props' ) ;
193
- if ( nextProps . shouldFocusWebview && isActiveTab ) {
193
+ if ( nextProperties . shouldFocusWebview && isActiveTab ) {
194
194
this . with ( ( webview , webContents ) => {
195
195
webview . focus ( ) ;
196
196
webContents . focus ( ) ;
@@ -199,39 +199,39 @@ export default class Tab extends Component<TabProps, TabState> {
199
199
}
200
200
if (
201
201
! this . props . shouldFocusWebview &&
202
- ! nextProps . shouldFocusWebview &&
203
- nextProps . isActiveTab
202
+ ! nextProperties . shouldFocusWebview &&
203
+ nextProperties . isActiveTab
204
204
) {
205
205
focusWebview ( true ) ;
206
206
}
207
- const nextId = nextProps . webId || { } ;
207
+ const nextId = nextProperties . webId || { } ;
208
208
const currentId = this . props . webId || { } ;
209
209
if ( nextId [ '@id' ] !== currentId [ '@id' ] ) {
210
210
if ( ! webview ) return ;
211
- logger . info ( 'New WebID set for ' , nextProps . url ) ;
212
- this . setCurrentWebId ( nextProps . webId ) ;
211
+ logger . info ( 'New WebID set for ' , nextProperties . url ) ;
212
+ this . setCurrentWebId ( nextProperties . webId ) ;
213
213
}
214
- if ( nextProps . url && nextProps . url !== url ) {
214
+ if ( nextProperties . url && nextProperties . url !== url ) {
215
215
if ( ! webview ) return ;
216
- const webviewSrc = parseURL ( webview . src ) ;
216
+ const webviewSource = parseURL ( webview . src ) ;
217
217
if (
218
- webviewSrc . href === '' ||
219
- `${ webviewSrc . protocol } ${ webviewSrc . hostname } ` === 'about:blank' ||
220
- urlHasChanged ( webview . src , nextProps . url )
218
+ webviewSource . href === '' ||
219
+ `${ webviewSource . protocol } ${ webviewSource . hostname } ` === 'about:blank' ||
220
+ urlHasChanged ( webview . src , nextProperties . url )
221
221
) {
222
- this . loadURL ( nextProps . url ) ;
222
+ this . loadURL ( nextProperties . url ) ;
223
223
}
224
224
}
225
- if ( ! shouldReload && nextProps . shouldReload ) {
226
- logger . verbose ( 'Should reload URL: ' , nextProps . url ) ;
225
+ if ( ! shouldReload && nextProperties . shouldReload ) {
226
+ logger . verbose ( 'Should reload URL: ' , nextProperties . url ) ;
227
227
this . reload ( ) ;
228
228
const tabUpdate = {
229
229
index,
230
230
shouldReload : false
231
231
} ;
232
232
updateTab ( tabUpdate ) ;
233
233
}
234
- if ( ! shouldToggleDevTools && nextProps . shouldToggleDevTools ) {
234
+ if ( ! shouldToggleDevelopmentTools && nextProperties . shouldToggleDevTools ) {
235
235
this . isDevToolsOpened ( ) ? this . closeDevTools ( ) : this . openDevTools ( ) ;
236
236
const tabUpdate = {
237
237
index,
@@ -241,7 +241,7 @@ export default class Tab extends Component<TabProps, TabState> {
241
241
}
242
242
}
243
243
244
- updateBrowserState ( props = { } ) {
244
+ updateBrowserState ( properties = { } ) {
245
245
const { webview } = this ;
246
246
if ( ! webview ) {
247
247
return ;
@@ -253,7 +253,7 @@ export default class Tab extends Component<TabProps, TabState> {
253
253
...this . state . browserState ,
254
254
canGoBack : webview . canGoBack ( ) ,
255
255
canGoForward : webview . canGoForward ( ) ,
256
- ...props
256
+ ...properties
257
257
} ;
258
258
this . setState ( { browserState } ) ;
259
259
}
@@ -268,17 +268,17 @@ export default class Tab extends Component<TabProps, TabState> {
268
268
}
269
269
this . updateBrowserState ( { loading : false , mountedAndReady : true } ) ;
270
270
if ( url && url !== 'about:blank' ) {
271
- this . loadURL ( url ) . catch ( err => console . info ( 'err in loadurl' , err ) ) ;
271
+ this . loadURL ( url ) . catch ( ( error ) => console . info ( 'err in loadurl' , error ) ) ;
272
272
this . setCurrentWebId ( null ) ;
273
273
}
274
274
}
275
275
276
- onCrash = e => {
276
+ onCrash = ( e ) => {
277
277
console . error ( e ) ;
278
278
logger . error ( 'The webview crashed' , e ) ;
279
279
} ;
280
280
281
- onGpuCrash = e => {
281
+ onGpuCrash = ( e ) => {
282
282
console . error ( e ) ;
283
283
logger . error ( 'The webview GPU crashed' , e ) ;
284
284
} ;
@@ -300,7 +300,7 @@ export default class Tab extends Component<TabProps, TabState> {
300
300
} ) ;
301
301
}
302
302
303
- didFailLoad ( err ) {
303
+ didFailLoad ( error ) {
304
304
const {
305
305
url,
306
306
index,
@@ -311,7 +311,10 @@ export default class Tab extends Component<TabProps, TabState> {
311
311
windowId
312
312
} = this . props ;
313
313
const { webview } = this ;
314
- const urlObj = stdUrl . parse ( url ) ;
314
+ const urlObject = stdUrl . parse ( url ) ;
315
+ const errorUrl = error . validatedURL ;
316
+
317
+ logger . info ( 'didfail load' , error ) ;
315
318
const renderError = ( header , subHeader ) => {
316
319
const errorAsHtml = ReactDOMServer . renderToStaticMarkup (
317
320
< Error error = { { header, subHeader } } />
@@ -328,31 +331,34 @@ export default class Tab extends Component<TabProps, TabState> {
328
331
}
329
332
` ) ;
330
333
} ;
331
- if ( urlObj . hostname === '127.0.0.1' || urlObj . hostname === 'localhost' ) {
334
+ if ( urlObject . hostname === '127.0.0.1' || urlObject . hostname === 'localhost' ) {
332
335
try {
333
336
renderError ( 'Page Load Failed' ) ;
334
337
} catch ( scriptError ) {
335
338
logger . error ( scriptError ) ;
336
339
}
337
340
return ;
338
341
}
339
- if ( err && err . errorDescription === 'ERR_INVALID_URL' ) {
342
+ if ( error && error . errorDescription === 'ERR_INVALID_URL' ) {
340
343
try {
341
344
renderError ( `Invalid URL: ${ url } ` ) ;
342
345
} catch ( scriptError ) {
343
346
logger . error ( scriptError ) ;
344
347
}
345
348
return ;
346
349
}
347
- if ( err && err . errorDescription === 'ERR_BLOCKED_BY_CLIENT' ) {
350
+ if ( error && error . errorDescription === 'ERR_BLOCKED_BY_CLIENT' ) {
348
351
const notification = {
349
352
title : 'Blocked URL' ,
350
- body : url
353
+ body : errorUrl
351
354
} ;
355
+
352
356
addNotification ( notification ) ;
353
- if ( this . state . browserState . canGoBack ) {
357
+
358
+ // check its the same link incase of double click
359
+ if ( this . state . browserState . canGoBack && ! urlHasChanged ( errorUrl , url ) ) {
354
360
tabBackwards ( { index, windowId } ) ;
355
- } else {
361
+ } else if ( ! this . state . browserState . canGoBack ) {
356
362
closeTab ( { index, windowId } ) ;
357
363
// add a fresh tab (should be only if no more tabs present)
358
364
addTab ( { url : 'about:blank' , windowId, isActiveTab : true } ) ;
@@ -453,10 +459,10 @@ export default class Tab extends Component<TabProps, TabState> {
453
459
454
460
didGetRedirectRequest ( e ) {
455
461
const { oldURL, newURL } = e ;
456
- const prev = oldURL ;
462
+ const previous = oldURL ;
457
463
const next = newURL ;
458
464
logger . info ( 'Webview: did get redirect request' ) ;
459
- if ( prev === this . state . browserState . url ) {
465
+ if ( previous === this . state . browserState . url ) {
460
466
this . updateBrowserState ( { redirects : [ next ] } ) ;
461
467
}
462
468
}
@@ -490,7 +496,7 @@ export default class Tab extends Component<TabProps, TabState> {
490
496
}
491
497
492
498
// TODO Move this functinoality to extensions
493
- updateTheIdInWebview = newWebId => {
499
+ updateTheIdInWebview = ( newWebId ) => {
494
500
const { updateTab, index, webId } = this . props ;
495
501
const { webview } = this ;
496
502
const theWebId = newWebId || webId ;
@@ -560,15 +566,15 @@ For updates or to submit ideas and suggestions, visit https://github.com/maidsaf
560
566
return frozen ;
561
567
}
562
568
563
- with ( cb , opts = { insist : false } ) {
569
+ with ( callback , options = { insist : false } ) {
564
570
const { webview } = this ;
565
571
if ( ! webview ) return ;
566
572
const webContents = webview . getWebContents ( ) ;
567
573
if ( ! webContents ) {
568
574
return ;
569
575
}
570
576
if ( webContents . isDestroyed ( ) ) return ;
571
- cb ( webview , webContents ) ;
577
+ callback ( webview , webContents ) ;
572
578
}
573
579
574
580
openDevTools ( ) {
@@ -580,28 +586,28 @@ For updates or to submit ideas and suggestions, visit https://github.com/maidsaf
580
586
}
581
587
582
588
stop ( ) {
583
- this . with ( wv => wv . stop ( ) ) ;
589
+ this . with ( ( wv ) => wv . stop ( ) ) ;
584
590
}
585
591
586
592
reload ( ) {
587
593
logger . info ( 'webview reloading' ) ;
588
- this . with ( wv => {
594
+ this . with ( ( wv ) => {
589
595
wv . reload ( ) ;
590
596
} ) ;
591
597
}
592
598
593
599
goBack ( e ) {
594
- this . with ( wv => wv . goBack ( ) ) ;
600
+ this . with ( ( wv ) => wv . goBack ( ) ) ;
595
601
}
596
602
597
603
goForward ( ) {
598
604
console . warn (
599
605
'Electron bug preventing goForward: https://github.com/electron/electron/issues/9999'
600
606
) ;
601
- this . with ( wv => wv . goForward ( ) ) ;
607
+ this . with ( ( wv ) => wv . goForward ( ) ) ;
602
608
}
603
609
604
- loadURL = async input => {
610
+ loadURL = async ( input ) => {
605
611
const { webview } = this ;
606
612
const url = addTrailingSlashIfNeeded ( input ) ;
607
613
logger . info ( 'Webview: loading url:' , url ) ;
@@ -628,21 +634,21 @@ For updates or to submit ideas and suggestions, visit https://github.com/maidsaf
628
634
}
629
635
630
636
if ( this . state && this . state . hasError ) {
631
- const err = this . state . theError ;
632
- const stringError = JSON . stringify ( err , [
637
+ const error = this . state . theError ;
638
+ const stringError = JSON . stringify ( error , [
633
639
'message' ,
634
640
'arguments' ,
635
641
'type' ,
636
642
'name'
637
643
] ) ;
638
- logger . error ( 'Error from Tab.jsx' , err ) ;
644
+ logger . error ( 'Error from Tab.jsx' , error ) ;
639
645
logger . error ( stringError ) ;
640
646
// You can render any custom fallback UI
641
647
return (
642
648
< div className = { moddedClass } >
643
649
< h4 > Something went wrong with this tab.</ h4 >
644
650
< span >
645
- { JSON . stringify ( err , [ 'message' , 'arguments' , 'type' , 'name' ] ) }
651
+ { JSON . stringify ( error , [ 'message' , 'arguments' , 'type' , 'name' ] ) }
646
652
</ span >
647
653
</ div >
648
654
) ;
@@ -655,7 +661,7 @@ For updates or to submit ideas and suggestions, visit https://github.com/maidsaf
655
661
tabIndex = "0"
656
662
preload = { injectPath }
657
663
partition = "persist:safe-tab"
658
- ref = { c => {
664
+ ref = { ( c ) => {
659
665
this . webview = c ;
660
666
} }
661
667
/>
0 commit comments