From af9aca98064382bbd9f376e2446c9813c00a05b3 Mon Sep 17 00:00:00 2001 From: Joe Fiorini Date: Thu, 5 Mar 2015 11:49:34 -0500 Subject: [PATCH] Allow app load to be suspended to let sourcemaps load --- awx/ui/static/js/app.js | 5 ++++- awx/ui/static/js/debug.js | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 awx/ui/static/js/debug.js diff --git a/awx/ui/static/js/app.js b/awx/ui/static/js/app.js index 162b3967c4..52c30101e9 100644 --- a/awx/ui/static/js/app.js +++ b/awx/ui/static/js/app.js @@ -56,7 +56,10 @@ import 'tower/shared/InventoryTree'; import 'tower/shared/Timer'; import 'tower/shared/Socket'; - +/*#if DEBUG#*/ +import {__deferLoadIfEnabled} from 'tower/debug'; +__deferLoadIfEnabled(); +/*#endif#*/ var tower = angular.module('Tower', [ 'ngRoute', diff --git a/awx/ui/static/js/debug.js b/awx/ui/static/js/debug.js new file mode 100644 index 0000000000..07255c050c --- /dev/null +++ b/awx/ui/static/js/debug.js @@ -0,0 +1,37 @@ +/********************************************* + * @ngdoc function + * @name __deferLoadIfEnabled + * @description + * + * This function only included in debug releases. + * + * This function exists to make it easier to debug when using sourcemaps. + * There is currently an issue in Chrome (and possibly other browsers) where + * breakpoints that hit before sourcemaps are downloaded do not work. + * + * Calling this function uses a feature in Angular that looks for a prefix on + * the `window.name` property to tell it to disable automatic loading of the app. + * + * If you need to debug code that runs at load time, first add: + * + * ?aw.suspend=true + * + * to the end of the URL. When you see the Tower logo loaded on an otherwise blank page, + * open the Dev Tools console and execute the code: + * + * angular.resumeBootstrap() + * + * This should continue loading the app and hit your breakpoint. + * + * For more information on how this works see https://docs.angularjs.org/guide/bootstrap +*/ +export function __deferLoadIfEnabled() { + + var deferPattern = /aw\.suspend=true/; + + if (deferPattern.test(window.location.search) || deferPattern.test(window.location.hash)) { + console.log('Deferred load due to "aw.suspend=true" in URL. Please execute `angular.resumeBootstrap()` to continue.'); + window.name = 'NG_DEFER_BOOTSTRAP!' + (window.name || ''); + } + +}