Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions notify-link-clicks-i18n/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# notify-link-clicks-i18n

**This add-on injects JavaScript into web pages. The `addons.mozilla.org` domain disallows this operation, so this add-on will not work properly when it's run on pages in the `addons.mozilla.org` domain.**
This add-on injects JavaScript into web pages that passes messages to the extension's background script when a link is clicked. The background script use the information in the message to create a notification. The extension illustrates how to localize the content of the notification as well as the extension's name and description.

## What it does

This extension includes:
This extension includes a:

* a content script, "content-script.js", that is injected into all pages
* a background script, "background-script.js"
* Content script, "content-script.js", that is injected into all pages.
* Background script, "background-script.js".

The content script listens for clicks in the page it's attached to.
If a click is on a link, the content script sends the link's href
to the background script.

**The `addons.mozilla.org` domain doesn't allow scripts to be injected into its pages. Therefore, this extension doesn't work on pages in the `addons.mozilla.org` domain.**

The background script listens for this message. When the background script
receives the message, it displays a notification containing the href.

Expand All @@ -21,7 +23,9 @@ localized into German, Dutch, and Japanese, as well as the default en-US.

# What it shows

* how to inject content scripts declaratively using manifest.json
* how to send messages from a content script to a background script
* how to display system notifications using the notifications API
* how to use the internationalization (i18n) system
This example extension shows how to:

* Inject content scripts declaratively using manifest.json.
* Send messages from a content script to a background script.
* Display system notifications using the notifications API.
* Use the internationalization (i18n) system.
2 changes: 1 addition & 1 deletion notify-link-clicks-i18n/background-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function notify(message) {
let content = browser.i18n.getMessage("notificationContent", message.url);
browser.notifications.create({
"type": "basic",
"iconUrl": browser.extension.getURL("icons/link-48.png"),
"iconUrl": browser.runtime.getURL("icons/link-48.png"),
"title": title,
"message": content
});
Expand Down
11 changes: 10 additions & 1 deletion notify-link-clicks-i18n/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{

"manifest_version": 2,
"manifest_version": 3,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need an ID in the manifest for MV3.

"name": "__MSG_extensionName__",
"description": "__MSG_extensionDescription__",
"version": "1.0",
Expand All @@ -9,6 +9,15 @@
"48": "icons/link-48.png"
},

"browser_specific_settings": {
"gecko": {
"id": "notify-link-clicks-i18n@mozilla.org",
"data_collection_permissions": {
"required": ["none"]
}
}
},

"permissions": ["notifications"],

"background": {
Expand Down
Loading