Closed Bug 1743083 Opened 3 years ago Closed 3 years ago

MessageHandler Modules can be initialized before the corresponding MessageHandler is ready

Categories

(Remote Protocol :: WebDriver BiDi, task, P2)

task
Points:
2

Tracking

(firefox96 fixed)

RESOLVED FIXED
96 Branch
Tracking Status
firefox96 --- fixed

People

(Reporter: jdescottes, Assigned: jdescottes)

Details

(Whiteboard: [bidi-m2-mvp])

Attachments

(1 file)

When creating modules to handle initial session data, the MessageHandler instance owning the module will not be fully initialized.

See the constructor for MessageHandler and WindowGlobalMessageHandler

class MessageHandler extends EventEmitter {
  constructor(sessionId, context, sessionDataItems) {
    super();
    // ...

    if (Array.isArray(sessionDataItems)) {
      this._applyInitialSessionDataItems(sessionDataItems);
    }
  }
class WindowGlobalMessageHandler extends MessageHandler {
  constructor() {
    super(...arguments);

    this._innerWindowId = this._context.window.windowGlobalChild.innerWindowId;
  }

If there is relevant session data, modules will be initialized at the end of the MessageHandler constructor, before the WindowGlobalMessageHandler could create its _innerWindowId. Meaning that if a module tries to access the information in their own constructor, they will get undefined.

The call to _applyInitialSessionDataItems should only be done after the constructor has returned, so that module are guaranteed to have a fully functional message handler instance.

Considering that MessageHandler are only instantiated from the MessageHandlerRegistry, I would simply suggest updating the following method:

_createMessageHandler(sessionId, sessionDataItems) {
    const messageHandler = new this._messageHandlerClass(
      sessionId,
      this._context,
      sessionDataItems
    );

to do

_createMessageHandler(sessionId, sessionDataItems) {
    const messageHandler = new this._messageHandlerClass(
      sessionId,
      this._context,
    );
    messageHandler.applyInitialSessionDataItems(sessionDataItems);

Yes, that sounds like the right approach to me too.

Assignee: nobody → jdescottes
Status: NEW → ASSIGNED
Pushed by jdescottes@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/0d8dbce59b1f [remote] Instantiate MessageHandler modules after constructor has returned r=webdriver-reviewers,whimboo
Points: --- → 2
Priority: -- → P2
Whiteboard: [webdriver:triage] → [bidi-m2-mvp]
Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 96 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: