diff --git a/src/extensions/default/bramble/lib/RemoteCommandHandler.js b/src/extensions/default/bramble/lib/RemoteCommandHandler.js index fecb08775ce..c99f7bc5e76 100644 --- a/src/extensions/default/bramble/lib/RemoteCommandHandler.js +++ b/src/extensions/default/bramble/lib/RemoteCommandHandler.js @@ -66,6 +66,8 @@ define(function (require, exports, module) { switch(command) { case "BRAMBLE_RELOAD": + // If JS is disabled, re-enable it just for this next reload. + HTMLRewriter.forceScriptsOnce(); PostMessageTransport.reload(); break; case "BRAMBLE_MOBILE_PREVIEW": diff --git a/src/filesystem/impls/filer/lib/HTMLRewriter.js b/src/filesystem/impls/filer/lib/HTMLRewriter.js index 3c61992ba51..8784401ab03 100644 --- a/src/filesystem/impls/filer/lib/HTMLRewriter.js +++ b/src/filesystem/impls/filer/lib/HTMLRewriter.js @@ -16,6 +16,13 @@ define(function (require, exports, module) { */ var jsEnabled = true; + /** + * Provides a way to force JS to run when disabled, but only once. + * Useful when we want to allow the user to manually refresh the page with UI + * vs. when we do it automatically. + */ + var jsEnabledOverride = false; + /** * Rewrite all external resources (links, scripts, img sources, ...) to * blob URL Objects from the fs. @@ -133,7 +140,7 @@ define(function (require, exports, module) { return; } - if(jsEnabled) { + if(jsEnabled || jsEnabledOverride) { if(element.getAttribute("type") === "text/x-scripts-disabled") { element.removeAttribute("type"); } @@ -202,6 +209,9 @@ define(function (require, exports, module) { doctype = (new XMLSerializer()).serializeToString(doc.doctype); } + // Reset the JS scripts override in case it was set on this run + jsEnabledOverride = false; + callback(err, doctype + html); }); } @@ -213,4 +223,7 @@ define(function (require, exports, module) { exports.disableScripts = function() { jsEnabled = false; }; + exports.forceScriptsOnce = function() { + jsEnabledOverride = true; + }; });