From fdfcf63f911cf91ecbd7958d86549cc15d517120 Mon Sep 17 00:00:00 2001 From: Hauke D Date: Mon, 13 Aug 2018 14:14:36 +0200 Subject: [PATCH] Fix URL resolution for file:// URLs (closes #1) Although this should fix the "null" appearing in the generated "baseurl", opening the pages via file:// will most likely still not work due to the Same-Origin Policy. --- web/webperl.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/web/webperl.js b/web/webperl.js index 552e41c..f99320e 100644 --- a/web/webperl.js +++ b/web/webperl.js @@ -171,7 +171,13 @@ Perl.init = function (readyCallback) { throw "Perl: can't call init in state "+Perl.state; Perl.changeState("Initializing"); var baseurl = new URL(getScriptURL()); - baseurl = baseurl.origin + baseurl.pathname.substring(0,baseurl.pathname.lastIndexOf('/')); + if (baseurl.protocol=='file:') + // Note that a lot of things still won't work for file:// URLs + // because of the Same-Origin Policy. + // see e.g. https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/CORSRequestNotHttp + baseurl = baseurl.href.substring(0,baseurl.href.lastIndexOf('/')); + else + baseurl = baseurl.origin + baseurl.pathname.substring(0,baseurl.pathname.lastIndexOf('/')); Perl.readyCallback = readyCallback; Module = { noInitialRun: true,