Files
webextensions-examples/notify-link-clicks/background-script.js
2016-01-14 15:06:44 -08:00

20 lines
523 B
JavaScript

/*
Assign `notify()` as a listener to messages from the content script.
*/
chrome.runtime.onMessage.addListener(notify);
/*
Log that we received the message.
Then display a notification. The notification contains the URL,
which we read from the message.
*/
function notify(message) {
console.log("background script received message");
chrome.notifications.create({
"type": "basic",
"iconUrl": chrome.extension.getURL("icons/link-48.png"),
"title": "You clicked a link!",
"message": message.url
});
}