mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-16 06:18:35 +02:00
add in a runtime example (#304)
* add in a runtime example * updated based on feedback
This commit is contained in:
14
runtime-examples/README.md
Normal file
14
runtime-examples/README.md
Normal file
@@ -0,0 +1,14 @@
|
||||
## What it does
|
||||
|
||||
Trigger an install notification when you install it. On the browser action text is
|
||||
shown showing when the background page was last loaded in minutes and seconds.
|
||||
|
||||
Clicking the browser action triggers a reload and updates the background page load time.
|
||||
|
||||
The notifications show the version of the extension by fetching the manifest.
|
||||
|
||||
## What it shows
|
||||
|
||||
Demonstration of some runtime and notification APIs.
|
||||
|
||||
Icon is from: https://www.iconfinder.com/icons/172151/run_icon#size=128
|
||||
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);
|
||||
17
runtime-examples/manifest.json
Normal file
17
runtime-examples/manifest.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"browser_action": {
|
||||
"default_icon": "run.png"
|
||||
},
|
||||
"description": "Demonstration of some runtime APIs",
|
||||
"homepage_url": "https://github.com/mdn/webextensions-examples/tree/master/runtime-examples",
|
||||
"manifest_version": 2,
|
||||
"name": "Runtime examples",
|
||||
"version": "1.0",
|
||||
"permissions": ["notifications"],
|
||||
"background": {
|
||||
"scripts": ["background.js"]
|
||||
},
|
||||
"icons": {
|
||||
"128": "run.png"
|
||||
}
|
||||
}
|
||||
BIN
runtime-examples/run.png
Normal file
BIN
runtime-examples/run.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.9 KiB |
Reference in New Issue
Block a user