send sample message on popup click to background.js

This commit is contained in:
abhijithvijayan 2019-10-25 16:29:59 +05:30
parent bc13bd909c
commit dd18c91b21
2 changed files with 32 additions and 2 deletions

View File

@ -1 +1,14 @@
console.log('Hello World from background main file!');
import browser from 'webextension-polyfill';
browser.runtime.onInstalled.addListener(() => {
// eslint-disable-next-line no-console
console.log('onInstalled....');
});
browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
// Do something with the message!
alert(request.url);
// And respond back to the sender.
return Promise.resolve('got your message, thanks!');
});

View File

@ -1 +1,18 @@
console.log('Hello World from popup main file!');
import browser from 'webextension-polyfill';
document.addEventListener('DOMContentLoaded', async () => {
const tabs = await browser.tabs.query({
active: true,
lastFocusedWindow: true,
});
const url = tabs.length && tabs[0].url;
const response = await browser.runtime.sendMessage({
msg: 'hello',
url,
});
// eslint-disable-next-line no-console
console.log(response);
});