0

Is there a way for a web extension add-on to listen for address fields changes when message is being edited? I need to listen for "to" address being added or changed.

Tried browser.compose.onComposeStateChanged - it get fired (sporadically) when address editing is started/in progress, but not when the editing is actually done.is

Aramir
  • 317
  • 2
  • 9

1 Answers1

0

The API is not guaranteed to fire after a user finishes editing the address field.

You could try setTimeout to poll for changes at regular intervals.

let toAddress = "";

browser.compose.onComposeStateChanged.addListener(function (tab) {
  browser.compose.getComposedDetails(tab.id).then((details) => {
    if (details.to !== toAddress) {
      console.log("To field changed: " + details.to);
      toAddress = details.to;
    }
  });
});

You can add this inside the onModify, onRemove, onAdd listeners depending on your needs.

Kreetchy
  • 688
  • 4
  • 14
  • I don't think there is `onComposed` event? `TypeError: browser.compose.onComposed is undefined` – Aramir Feb 19 '23 at 21:59
  • My bad, you should keep your `browser.compose.onComposeStateChanged`. The goal of this answer was to propose a solution to keep firiing the event anyways, so I still believe polling for the event should solve your issue. – Kreetchy Feb 20 '23 at 00:33