Skip to content
This repository was archived by the owner on Nov 15, 2017. It is now read-only.

Commit 6344dee

Browse files
committed
this fixes #171
1 parent da2911f commit 6344dee

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

js/traffic.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,45 @@ function onHeadersReceivedHandler(details) {
475475

476476
/******************************************************************************/
477477

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+
478517
var webRequestHandlerRequirements = {
479518
'tabsBound': 0,
480519
'listsLoaded': 0
@@ -533,6 +572,16 @@ function startWebRequestHandler(from) {
533572
},
534573
['blocking', 'responseHeaders']
535574
);
575+
576+
chrome.webRequest.onErrorOccurred.addListener(
577+
onErrorOccurredHandler,
578+
{
579+
'urls': [
580+
"http://*/*",
581+
"https://*/*"
582+
]
583+
}
584+
);
536585
}
537586

538587
/******************************************************************************/

0 commit comments

Comments
 (0)