Bug 1702511 - [devtools] Flush resources when receiving the will-navigate event. r=jdescottes,nchevobbe
authorAlexandre Poirot <poirot.alex@gmail.com>
Mon, 31 May 2021 20:29:55 +0000
changeset 581530 8967dc205c2191c67b30baa1960b842861292a8c
parent 581529 a4562f19df5477490c07d91f257abe100c456dfe
child 581531 90d2e0a0ead6aaab6dfaadb53a5354b22a94f681
push id144084
push userapoirot@mozilla.com
push dateMon, 31 May 2021 20:32:33 +0000
treeherderautoland@f7988048b5d7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdescottes, nchevobbe
bugs1702511
milestone91.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1702511 - [devtools] Flush resources when receiving the will-navigate event. r=jdescottes,nchevobbe That's to ensure clearing the panels sooner than later. A few tests depend on this. Without that, target actor's "navigate" event, which isn't throttled, fires *before* DOCUMENT_EVENT's will-navigate. That ends up being a logic issue in the console code. Differential Revision: https://phabricator.services.mozilla.com/D112230
devtools/shared/commands/resource/resource-command.js
--- a/devtools/shared/commands/resource/resource-command.js
+++ b/devtools/shared/commands/resource/resource-command.js
@@ -449,16 +449,17 @@ class ResourceCommand {
    *        A dictionary object with only one of these two attributes:
    *        - targetFront: a Target Front, if the resource is watched from the target process or thread
    *        - watcherFront: a Watcher Front, if the resource is watched from the parent process
    * @param {Array<json/Front>} resources
    *        Depending on the resource Type, it can be an Array composed of either JSON objects or Fronts,
    *        which describes the resource.
    */
   async _onResourceAvailable({ targetFront, watcherFront }, resources) {
+    let includesDocumentEventWillNavigate = false;
     for (let resource of resources) {
       const { resourceType } = resource;
 
       if (watcherFront) {
         targetFront = await this._getTargetForWatcherResource(resource);
       }
 
       // isAlreadyExistingResource indicates that the resources already existed before
@@ -477,21 +478,35 @@ class ResourceCommand {
         resource = ResourceTransformers[resourceType]({
           resource,
           targetCommand: this.targetCommand,
           targetFront,
           watcherFront: this.watcherFront,
         });
       }
 
+      if (
+        resourceType == ResourceCommand.TYPES.DOCUMENT_EVENT &&
+        resource.name == "will-navigate"
+      ) {
+        includesDocumentEventWillNavigate = true;
+      }
+
       this._queueResourceEvent("available", resourceType, resource);
 
       this._cache.push(resource);
     }
-    this._throttledNotifyWatchers();
+    // If we receive the DOCUMENT_EVENT for will-navigate,
+    // flush immediately the resources in order to notify about the navigation sooner than later.
+    // (this is especially useful for tests, even if they should probably avoid depending on this...)
+    if (includesDocumentEventWillNavigate) {
+      this._notifyWatchers();
+    } else {
+      this._throttledNotifyWatchers();
+    }
   }
 
   /**
    * Method called either by:
    * - the backward compatibility code (LegacyListeners)
    * - target actors RDP events
    * Called everytime a resource is updated in the remote target.
    *