From 2dd404db0fb8d945613a38ac35eba7a70dcfaad2 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Mon, 10 Oct 2016 14:02:56 -0700 Subject: [PATCH] Add async function version of message listener example. --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 0565c72..b7628e4 100644 --- a/README.md +++ b/README.md @@ -158,4 +158,17 @@ browser.runtime.onMessage.addListener(msg => { }); ``` +or: + +```javascript +browser.runtime.onMessage.addListener(async function(msg) { + if (msg == "get-ids") { + let {idPattern} = await browser.storage.get("idPattern"); + + return Array.from(document.querySelectorAll(idPattern), + elem => elem.textContent); + } +}); +``` + Or vice versa.