Skip to content

Instantly share code, notes, and snippets.

@daftspaniel
Created March 27, 2018 18:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daftspaniel/a894452746becd83bebc7a8ec63e7105 to your computer and use it in GitHub Desktop.
Save daftspaniel/a894452746becd83bebc7a8ec63e7105 to your computer and use it in GitHub Desktop.
(function() {
var _currentDirectory = (function () {
var _url;
var lines = new Error().stack.split('\n');
function lookupUrl() {
if (lines.length > 2) {
var match = lines[1].match(/^\s+at (.+):\d+:\d+$/);
// Chrome.
if (match) return match[1];
// Chrome nested eval case.
match = lines[1].match(/^\s+at eval [(](.+):\d+:\d+[)]$/);
if (match) return match[1];
// Edge.
match = lines[1].match(/^\s+at.+\((.+):\d+:\d+\)$/);
if (match) return match[1];
// Firefox.
match = lines[0].match(/[<][@](.+):\d+:\d+$/)
if (match) return match[1];
}
// Safari.
return lines[0].match(/(.+):\d+:\d+$/)[1];
}
_url = lookupUrl();
var lastSlash = _url.lastIndexOf('/');
if (lastSlash == -1) return _url;
var currentDirectory = _url.substring(0, lastSlash + 1);
return currentDirectory;
})();
// Attempt to detect --precompiled mode for tests, and set the base url
// appropriately, otherwise set it to "/".
var baseUrl = (function() {
var pathParts = location.pathname.split("/");
if (pathParts[0] == "") {
pathParts.shift();
}
var baseUrl;
if (pathParts.length > 1 && pathParts[1] == "test") {
return "/" + pathParts.slice(0, 2).join("/") + "/";
}
return "/";
}());
var el;
el = document.createElement("script");
el.defer = true;
el.async = false;
el.src =
baseUrl + "packages/$sdk/dev_compiler/web/dart_stack_trace_mapper.js";
document.head.appendChild(el);
el = document.createElement("script");
el.defer = true;
el.async = false;
el.src = baseUrl + "packages/$sdk/dev_compiler/amd/require.js";
el.setAttribute("data-main", _currentDirectory + "pwa.dart.bootstrap");
document.head.appendChild(el);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment