mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-17 14:59:12 +02:00
add in a runtime example (#304)
* add in a runtime example * updated based on feedback
This commit is contained in:
17
runtime-examples/background.js
Normal file
17
runtime-examples/background.js
Normal file
@@ -0,0 +1,17 @@
|
||||
let loadTime = new Date();
|
||||
let manifest = browser.runtime.getManifest();
|
||||
|
||||
function onInstalledNotification(details) {
|
||||
browser.notifications.create('onInstalled', {
|
||||
title: `Runtime Examples version: ${manifest.version}`,
|
||||
message: `onInstalled has been called, background page loaded at ${loadTime.getHours()}:${loadTime.getMinutes()}`,
|
||||
type: 'basic'
|
||||
});
|
||||
}
|
||||
|
||||
function onClick() {
|
||||
browser.runtime.reload();
|
||||
}
|
||||
|
||||
browser.browserAction.onClicked.addListener(onClick);
|
||||
browser.runtime.onInstalled.addListener(onInstalledNotification);
|
||||
Reference in New Issue
Block a user