@@ -454,24 +454,6 @@ define(function LiveDevelopment(require, exports, module) {
454454 // However, the link refers to the Chrome Extension API, it may not apply 100% to the Inspector API
455455 }
456456
457- /** Triggered by Inspector.connect */
458- function _onConnect ( event ) {
459- $ ( Inspector . Inspector ) . on ( "detached" , _onDetached ) ;
460-
461- // Load agents
462- _setStatus ( STATUS_LOADING_AGENTS ) ;
463- var promises = loadAgents ( ) ;
464- $ . when . apply ( undefined , promises ) . done ( _onLoad ) . fail ( _onError ) ;
465-
466- // Load the right document (some agents are waiting for the page's load event)
467- var doc = _getCurrentDocument ( ) ;
468- if ( doc ) {
469- Inspector . Page . navigate ( doc . root . url ) ;
470- } else {
471- Inspector . Page . reload ( ) ;
472- }
473- }
474-
475457 /** Triggered by Inspector.disconnect */
476458 function _onDisconnect ( event ) {
477459 $ ( Inspector . Inspector ) . off ( "detached" , _onDetached ) ;
@@ -532,10 +514,11 @@ define(function LiveDevelopment(require, exports, module) {
532514 // helper function that actually does the launch once we are sure we have
533515 // a doc and the server for that doc is up and running.
534516 function doLaunchAfterServerReady ( ) {
535- var url = doc . root . url ;
517+ var targetUrl = doc . root . url ;
518+ var interstitialUrl = launcherUrl + "?" + encodeURIComponent ( targetUrl ) ;
536519
537520 _setStatus ( STATUS_CONNECTING ) ;
538- Inspector . connectToURL ( url ) . done ( result . resolve ) . fail ( function onConnectFail ( err ) {
521+ Inspector . connectToURL ( interstitialUrl ) . done ( result . resolve ) . fail ( function onConnectFail ( err ) {
539522 if ( err === "CANCEL" ) {
540523 result . reject ( err ) ;
541524 return ;
@@ -572,10 +555,8 @@ define(function LiveDevelopment(require, exports, module) {
572555 retryCount ++ ;
573556
574557 if ( ! browserStarted && exports . status !== STATUS_ERROR ) {
575- url = launcherUrl + "?" + encodeURIComponent ( url ) ;
576-
577558 NativeApp . openLiveBrowser (
578- url ,
559+ interstitialUrl ,
579560 true // enable remote debugging
580561 )
581562 . done ( function ( ) {
@@ -608,7 +589,7 @@ define(function LiveDevelopment(require, exports, module) {
608589
609590 if ( exports . status !== STATUS_ERROR ) {
610591 window . setTimeout ( function retryConnect ( ) {
611- Inspector . connectToURL ( url ) . done ( result . resolve ) . fail ( onConnectFail ) ;
592+ Inspector . connectToURL ( interstitialUrl ) . done ( result . resolve ) . fail ( onConnectFail ) ;
612593 } , 500 ) ;
613594 }
614595 } ) ;
@@ -675,6 +656,74 @@ define(function LiveDevelopment(require, exports, module) {
675656 agents . highlight . redraw ( ) ;
676657 }
677658 }
659+
660+ /** Triggered by Inspector.connect */
661+ function _onConnect ( event ) {
662+
663+ /*
664+ * Create a promise that resolves when the interstitial page has
665+ * finished loading.
666+ *
667+ * @return {jQuery.Promise }
668+ */
669+ function waitForInterstitialPageLoad ( ) {
670+ var deferred = $ . Deferred ( ) ,
671+ keepPolling = true ,
672+ timer = window . setTimeout ( function ( ) {
673+ keepPolling = false ;
674+ deferred . reject ( ) ;
675+ } , 10000 ) ; // 10 seconds
676+
677+ /*
678+ * Asynchronously check to see if the interstitial page has
679+ * finished loading; if not, check again until timing out.
680+ */
681+ function pollInterstitialPage ( ) {
682+ if ( keepPolling && Inspector . connected ( ) ) {
683+ Inspector . Runtime . evaluate ( "window.isBracketsLiveDevelopmentInterstitialPageLoaded" , function ( response ) {
684+ var result = response . result ;
685+
686+ if ( result . type === "boolean" && result . value ) {
687+ window . clearTimeout ( timer ) ;
688+ deferred . resolve ( ) ;
689+ } else {
690+ pollInterstitialPage ( ) ;
691+ }
692+ } ) ;
693+ } else {
694+ deferred . reject ( ) ;
695+ }
696+ }
697+
698+ pollInterstitialPage ( ) ;
699+ return deferred . promise ( ) ;
700+ }
701+
702+ /*
703+ * Load agents and navigate to the target document once the
704+ * interstitial page has finished loading.
705+ */
706+ function onInterstitialPageLoad ( ) {
707+ // Load agents
708+ _setStatus ( STATUS_LOADING_AGENTS ) ;
709+ var promises = loadAgents ( ) ;
710+ $ . when . apply ( undefined , promises ) . done ( _onLoad ) . fail ( _onError ) ;
711+
712+ // Load the right document (some agents are waiting for the page's load event)
713+ var doc = _getCurrentDocument ( ) ;
714+ if ( doc ) {
715+ Inspector . Page . navigate ( doc . root . url ) ;
716+ } else {
717+ close ( ) ;
718+ }
719+ }
720+
721+ $ ( Inspector . Inspector ) . on ( "detached" , _onDetached ) ;
722+
723+ var interstitialPageLoad = waitForInterstitialPageLoad ( ) ;
724+ interstitialPageLoad . fail ( close ) ;
725+ interstitialPageLoad . done ( onInterstitialPageLoad ) ;
726+ }
678727
679728 /** Triggered by a document change from the DocumentManager */
680729 function _onDocumentChange ( ) {
0 commit comments