From 4ccb9bd0d492fe39bc80fb685daf82d93fbc11e5 Mon Sep 17 00:00:00 2001 From: gorhill Date: Tue, 15 Nov 2016 10:05:05 -0500 Subject: [PATCH] fix uncaught exception --- src/js/contentscript-end.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/js/contentscript-end.js b/src/js/contentscript-end.js index d533379..000b9b5 100644 --- a/src/js/contentscript-end.js +++ b/src/js/contentscript-end.js @@ -155,7 +155,7 @@ var collapser = (function() { var collapse = response.collapse; var placeholders = response.placeholders; var i = requests.length; - var request, entry, target, tagName, docurl; + var request, entry, target, tagName, docurl, replaced; while ( i-- ) { request = requests[i]; if ( pendingRequests.hasOwnProperty(request.id) === false ) { @@ -183,11 +183,17 @@ var collapser = (function() { // Special case: iframe if ( tagName === 'iframe' ) { docurl = 'data:text/html,' + encodeURIComponent(placeholders.iframe.replace(reURLplaceholder, request.url)); + replaced = false; // Using contentWindow.location prevent tainting browser // history -- i.e. breaking back button (seen on Chromium). if ( target.contentWindow ) { - target.contentWindow.location.replace(docurl); - } else { + try { + target.contentWindow.location.replace(docurl); + replaced = true; + } catch(ex) { + } + } + if ( !replaced ) { target.setAttribute('src', docurl); } continue;