Open Bug 1644192 Opened 2 years ago Updated 1 year ago

[meta] Implement Storage data listening via the ResourceWatcher API on the actor side


(DevTools :: Storage Inspector, enhancement, P3)



(Not tracked)


(Reporter: ochameau, Unassigned)


(Depends on 1 open bug, Blocks 1 open bug)


(Keywords: meta, Whiteboard: [not-a-fission-bug])


(4 obsolete files)

The goal here is to implement the STORAGE resource from the actor side.
This is about replicating the current behavior, implemented in bug 1625935.
But instead of having a wrapper on the client side to morph the legacy StorageFront methods (i.e. the legacy listener code),
we would implement an actor API matching ResourceWatcher API (i.e. watch and unwatch).

This would be about implementing a server side equivalent of this legacy listener code:
In a new server side module:

This module would typicaly look like this:

const { TYPES } = require("devtools/server/actors/resources/index");

class MyResourceWatcher {
   * Start watching for all ${MY_RESOURCE_TYPE} related to a given Target Actor.
   * This will notify about existing ${MY_RESOURCE_TYPE}, but also the one created in future.
   * @param TargetActor targetActor
   *        The target actor from which we should observe console messages
   * @param Object options
   *        Dictionary object with following attributes:
   *        - onAvailable: mandatory function
   *          This will be called for each resource.
  constructor(targetActor, { onAvailable }) {
    // In most cases, we already have some helper class which helps observing one resource
    // that we can spawn like this:
    // Note that it may often be easier to merge such `MyResourceListener` into this `MyResourceWatcher` class!
    const listener = new MyResourceListener(
      ...  /* whatever is useful for your observation */
    // Forward all future resources being observed to the upper layer calling this module,
    // via `onAvailable` callback argument.
    // I'm using EventEmitter API here, but the API may different,
    // based on the platform API we have to use to observe the resource.
    listener.on("one-of-my-resource-is-created", resource => {
      // We have to ensure that each resource object has a valid `resourceType` attribute
      resource.resourceType = TYPES.MY_RESOURCE_TYPE;
    // Also forward all resources which already exist when we are calling this method
    // (if any exists)
    const cachedResources = listener.getAllAlreadyExistingOrCachedResources();
    for(const resource of cachedResources) {
      resource.resourceType = TYPES.MY_RESOURCE_TYPE;
    // Save the listener in order to destroy/stop watching later on.
    this.listener = listener;

   * Stop watching for ${MY_RESOURCE_TYPE}.
  destroy() {
    if (this.listener) {
module.exports = MyResourceWatcher;

An important goal here is to emit the exact same resource object that the legacy listener is passing to its onAvailable callback.
Same attributes, same values, ...

Bug 1644185 could be used as a template. As it did this work for PLATFORM_MESSAGE resource type.

The main reason to do this is to be able to start listening to the resource before the page starts loading.
Thanks to the framework work done in bug 1620243, this MyResourceWatcher class will be instantiated before the page starts
loading and possibly as early as the content process just started.
This wasn't the case with legacy actor APIs like WebConsoleActor.startListeners, ThreadActor.attachThread, ...
We were calling these methods too late, only after the frontend is notify about the existance of the target, so, late after the page started loading.

You will also have to register this new module in this registry:

  • Add a new entry in TYPES object.
  • Register your new resource watcher module into Resources object.

Last but not least, it is probably a good time to review the existing tests for this Resource:
And ensure that it has a good coverage.
You would especially have to migrate all Client/Front tests, which were testing the backend behavior via targetFront.getFront("myfront").
All these tests will be removed, once we drop the legacy listeners. Because we are going to drop the server API that we no longer use.
Like WebConsoleActor/Front.getCachedMessage(), WebConsoleActor/Front.startListeners(), ThreadActor/Front.sources(), ThreadActor/, ...

Tracking dt-fission-m2 bugs for Fission Nightly (M6c)

Fission Milestone: --- → M6c
Depends on: 1646854

Depends on D84594

Blocks: 1657101
Depends on: 1657104
Depends on: 1657153
Attachment #9167745 - Attachment is obsolete: true
Attachment #9167697 - Attachment is obsolete: true
Whiteboard: dt-fission-m2-mvp → dt-fission-m2-reserve
Whiteboard: dt-fission-m2-reserve → dt-fission-m2-mvp
Depends on: 1666519
Depends on: 1666528
Depends on: 1666533
Depends on: 1666532
Depends on: 1666534
Depends on: 1666529
Keywords: meta
Summary: Implement Storage data listening via the ResourceWatcher API on the actor side → [meta] Implement Storage data listening via the ResourceWatcher API on the actor side
Whiteboard: dt-fission-m2-mvp

Clearing Fission Milestone flag. Since the dt-fission-m2-mvp whiteboard tag was removed, I assume this bug no longer needs to block Fission.

Fission Milestone: M6c → ---
Attachment #9166578 - Attachment is obsolete: true
Attachment #9158988 - Attachment is obsolete: true
Depends on: 1673821
Depends on: 1677697
Depends on: 1685474
Blocks: 1698891
Whiteboard: [not-a-fission-bug]
No longer blocks: 1698891
You need to log in before you can comment on or make changes to this bug.