onMessage()
Register one and only one listener, per messageId per context. That will be called upon sendMessage
from other side.
Optionally, send a response to sender by returning any value or if async a Promise
.
messageId
Required | string
Any string
that both sides of your extension agree on. Could be get-flag-count
or getFlagCount
or GET_FLAG_COUNT
, as long as it's same in sender's sendMessage
call.
callback
Required | fn
A callback function webext-bridge
should call when a message is received with same messageId
. The callback function will be called with one argument, a message
which has sender
, data
and timestamp
as its properties.
Optionally, this callback can return a value or a Promise
, resolved value will sent as reply to sender.
Read security note before using this.