@@ -48,10 +48,7 @@ const { safeAsyncMethod } = require("devtools/shared/async-utils");
4848window . Application = {
4949 async bootstrap ( { toolbox, commands, panel } ) {
5050 // bind event handlers to `this`
51- this . handleOnNavigate = this . handleOnNavigate . bind ( this ) ;
5251 this . updateDomain = this . updateDomain . bind ( this ) ;
53- this . onTargetAvailable = this . onTargetAvailable . bind ( this ) ;
54- this . onTargetDestroyed = this . onTargetDestroyed . bind ( this ) ;
5552
5653 // wrap updateWorkers to swallow rejections occurring after destroy
5754 this . safeUpdateWorkers = safeAsyncMethod (
@@ -80,12 +77,12 @@ window.Application = {
8077 canDebugServiceWorkers && services . features . doesDebuggerSupportWorkers
8178 ) ;
8279
83- // awaiting for watchTargets will return the targets that are currently
84- // available, so we can have our first render with all the data ready
85- await this . _commands . targetCommand . watchTargets (
86- [ this . _commands . targetCommand . TYPES . FRAME ] ,
87- this . onTargetAvailable ,
88- this . onTargetDestroyed
80+ this . onResourceAvailable = this . onResourceAvailable . bind ( this ) ;
81+ await this . _commands . resourceCommand . watchResources (
82+ [ this . _commands . resourceCommand . TYPES . DOCUMENT_EVENT ] ,
83+ {
84+ onAvailable : this . onResourceAvailable ,
85+ }
8986 ) ;
9087
9188 // Render the root Application component.
@@ -97,11 +94,6 @@ window.Application = {
9794 render ( Provider ( { store : this . store } , app ) , this . mount ) ;
9895 } ,
9996
100- handleOnNavigate ( ) {
101- this . updateDomain ( ) ;
102- this . actions . resetManifest ( ) ;
103- } ,
104-
10597 async updateWorkers ( ) {
10698 const registrationsWithWorkers = await this . client . mainRoot . listAllServiceWorkers ( ) ;
10799 this . actions . updateWorkers ( registrationsWithWorkers ) ;
@@ -111,42 +103,33 @@ window.Application = {
111103 this . actions . updateDomain ( this . toolbox . target . url ) ;
112104 } ,
113105
114- setupTarget ( targetFront ) {
115- this . handleOnNavigate ( ) ; // update domain and manifest for the new target
116- targetFront . on ( "navigate" , this . handleOnNavigate ) ;
117- } ,
118-
119- cleanUpTarget ( targetFront ) {
120- targetFront . off ( "navigate" , this . handleOnNavigate ) ;
121- } ,
122-
123- onTargetAvailable ( { targetFront } ) {
124- if ( ! targetFront . isTopLevel ) {
125- return ; // ignore target frames that are not top level for now
126- }
127-
128- this . setupTarget ( targetFront ) ;
106+ handleOnNavigate ( ) {
107+ this . updateDomain ( ) ;
108+ this . actions . resetManifest ( ) ;
129109 } ,
130110
131- onTargetDestroyed ( { targetFront } ) {
132- if ( ! targetFront . isTopLevel ) {
133- return ; // ignore target frames that are not top level for now
111+ onResourceAvailable ( resources ) {
112+ // Only consider top level document, and ignore remote iframes top document
113+ const hasDocumentDomComplete = resources . some (
114+ resource =>
115+ resource . resourceType ===
116+ this . _commands . resourceCommand . TYPES . DOCUMENT_EVENT &&
117+ resource . name === "dom-complete" &&
118+ resource . targetFront . isTopLevel
119+ ) ;
120+ if ( hasDocumentDomComplete ) {
121+ this . handleOnNavigate ( ) ; // update domain and manifest for the new target
134122 }
135-
136- this . cleanUpTarget ( targetFront ) ;
137123 } ,
138124
139125 destroy ( ) {
140126 this . workersListener . removeListener ( ) ;
141127
142- this . _commands . targetCommand . unwatchTargets (
143- [ this . _commands . targetCommand . TYPES . FRAME ] ,
144- this . onTargetAvailable ,
145- this . onTargetDestroyed
128+ this . _commands . resourceCommand . unwatchResources (
129+ [ this . _commands . resourceCommand . TYPES . DOCUMENT_EVENT ] ,
130+ { onAvailable : this . onResourceAvailable }
146131 ) ;
147132
148- this . cleanUpTarget ( this . toolbox . target ) ;
149-
150133 unmountComponentAtNode ( this . mount ) ;
151134 this . mount = null ;
152135 this . toolbox = null ;
0 commit comments