@@ -475,6 +475,45 @@ function onHeadersReceivedHandler(details) {
475
475
476
476
/******************************************************************************/
477
477
478
+ // As per Chrome API doc, webRequest.onErrorOccurred event is the last
479
+ // one called in the sequence of webRequest events.
480
+ // http://developer.chrome.com/extensions/webRequest.html
481
+
482
+ function onErrorOccurredHandler ( details ) {
483
+ // console.debug('onErrorOccurred()> "%s": %o', details.url, details);
484
+
485
+ // Ignore all that is not a main document
486
+ if ( details . type !== 'main_frame' || details . parentFrameId >= 0 ) {
487
+ return ;
488
+ }
489
+
490
+ var pageStats = pageStatsFromPageUrl ( details . url ) ;
491
+ if ( ! pageStats ) {
492
+ return ;
493
+ }
494
+
495
+ // rhill 2014-01-28: Unwind the stack of redirects if any. Chromium will
496
+ // emit an error when a web page redirects apparently endlessly, so
497
+ // we need to unravel and report all these redirects upon error.
498
+ // https://github.com/gorhill/httpswitchboard/issues/171
499
+ var httpsb = HTTPSB ;
500
+ var requestURL = uriTools . normalizeURI ( details . url ) ;
501
+ var mainFrameStack = [ requestURL ] ;
502
+ var destinationURL = requestURL ;
503
+ var sourceURL ;
504
+ while ( sourceURL = httpsb . redirectRequests [ destinationURL ] ) {
505
+ mainFrameStack . push ( sourceURL ) ;
506
+ delete httpsb . redirectRequests [ destinationURL ] ;
507
+ destinationURL = sourceURL ;
508
+ }
509
+
510
+ while ( destinationURL = mainFrameStack . pop ( ) ) {
511
+ pageStats . recordRequest ( 'main_frame' , destinationURL , false ) ;
512
+ }
513
+ }
514
+
515
+ /******************************************************************************/
516
+
478
517
var webRequestHandlerRequirements = {
479
518
'tabsBound' : 0 ,
480
519
'listsLoaded' : 0
@@ -533,6 +572,16 @@ function startWebRequestHandler(from) {
533
572
} ,
534
573
[ 'blocking' , 'responseHeaders' ]
535
574
) ;
575
+
576
+ chrome . webRequest . onErrorOccurred . addListener (
577
+ onErrorOccurredHandler ,
578
+ {
579
+ 'urls' : [
580
+ "http://*/*" ,
581
+ "https://*/*"
582
+ ]
583
+ }
584
+ ) ;
536
585
}
537
586
538
587
/******************************************************************************/
0 commit comments