Listening for changes in the address fields

46 Views Asked by At

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

1

There are 1 best solutions below

2
On

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.getComposeDetails(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.