message passing between background and content

This commit is contained in:
Shin'ya Ueoka 2017-08-12 11:08:43 +09:00
parent d169661e03
commit e73d405c56
6 changed files with 19 additions and 23 deletions

9
src/content/index.js Normal file
View file

@ -0,0 +1,9 @@
window.addEventListener("keypress", (e) => {
browser.runtime.sendMessage({
which: e.which || e.keyCode,
}).then((msg) => {
console.log(`Message from the background script: ${msg.response}`);
}, (err) => {
console.log(`Error: ${err}`);
});
});