Skip to content

Commit

Permalink
Update eventListeners.rst
Browse files Browse the repository at this point in the history
  • Loading branch information
jobisoft committed Dec 1, 2023
1 parent cb9704d commit 782f226
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions how-to/eventListeners.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ WebExtensions can react on events by attaching a listener. Consider the :ref:`me
.. code-block:: javascript
async function menuListener(info, tab) {
...
// do something with the info and tab parameters received from the event
// Do something with the info and tab parameters
// received from the event.
}
messenger.menus.onClicked.addListener(menuListener);
Expand All @@ -18,6 +18,23 @@ Alternative implementation using an anonymous arrow function:
.. code-block:: javascript
messenger.menus.onClicked.addListener(async (info, tab) => {
// do something with the info and tab parameters received from the event
...
// Do something with the info and tab parameters
// received from the event.
});
Events with additional parameters
=================================

Some events support additional parameters, for example the :ref:`tabs.onUpdated` event.

The additional parameter ``filter`` is the second parameter of the ``addListener``
function, specifying what type of update events should be reported.

.. code-block:: javascript
async function listener(tabId, changeInfo) {
// Do something with the tabId and changeInfo parameters
// received from the event.
}
messenger.tabs.onUpdated.addListener(listener, {tabId: 5});

0 comments on commit 782f226

Please sign in to comment.