-
Notifications
You must be signed in to change notification settings - Fork 2.7k
MDN get started tutorial examples to manifest V3 #608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rebloor
wants to merge
7
commits into
mdn:main
Choose a base branch
from
rebloor:Content-issue-41050-tutorial-examples-to-manifest-V3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
da2172c
MDN get started tutorial examples to manifest V3
rebloor 8b43ca9
Migrate to Scripting API
dotproto 325f8cb
Merge pull request #1 from dotproto/pr-608
rebloor 0892301
Updated to readmes and code comments
rebloor 313fb9a
Apply suggestions to readmes from review
rebloor e3206f1
Convert choose_beast.js to async
rebloor 4a5d71e
Apply suggestions from review
rebloor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,40 +1,41 @@ | ||
| # beastify | ||
|
|
||
| This extension used a tootlbar button to enable the section of beast that replaces the content of the active web page. | ||
|
|
||
| ## What it does ## | ||
|
|
||
| The extension includes: | ||
|
|
||
| * a browser action with a popup including HTML, CSS, and JS | ||
| * a content script | ||
| * three images, each of a different beast, packaged as web accessible resources | ||
| * An action with a popup that includes HTML, CSS, and JavaScript. | ||
| * A content script. | ||
| * Three images, each of a beast, packaged as web accessible resources. | ||
|
|
||
| When the user clicks the browser action button, the popup is shown, enabling | ||
| the user to choose one of three beasts. | ||
| When the user clicks the action (toolbar button), the extension's popup opens, enabling the user to choose one of three beasts. | ||
|
|
||
| When it is shown, the popup injects a content script into the current page. | ||
| When opened, the popup injects a content script into the active page. | ||
|
|
||
| When the user chooses a beast, the extension sends the content script a message containing | ||
| the name of the chosen beast. | ||
| When the user chooses a beast, the extension sends the content script a message containing the name of the chosen beast. | ||
|
|
||
| When the content script receives this message, it replaces the current page | ||
| content with an image of the chosen beast. | ||
| When the content script receives this message, it replaces the active page content with an image of the chosen beast. | ||
|
|
||
| When the user clicks the reset button, the page reloads, and reverts to its original form. | ||
| When the user clicks the reset button, the page reloads and reverts to its original form. | ||
|
|
||
| Note that: | ||
|
|
||
| * if the user reloads the tab, or switches tabs, while the popup is open, then the popup won't be able to beastify the page any more (because the content script was injected into the original tab). | ||
| * If the user reloads the tab, or switches tabs, while the popup is open, then the popup can't beastify the page (because the content script was injected into the original tab). | ||
|
|
||
| * by default [`tabs.executeScript()`](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/tabs/executeScript) injects the script only when the web page and its resources have finished loading. This means that clicks in the popup will have no effect until the page has finished loading. | ||
| * By default, [`scripting.executeScript()`](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/scripting/executeScript) injects the script only when the web page and its resources have finished loading. This means that clicks in the popup have no effect until the page has finished loading. | ||
|
|
||
| * it's not possible to inject content scripts into certain pages, including privileged browser pages like "about:debugging" and the [addons.mozilla.org](https://addons.mozilla.org/) website. If the user clicks the beastify icon when such a page is loaded into the active tab, the popup displays an error message. | ||
| * Browsers don't allow extensions to inject content scripts into specific pages. In Firefox, this includes privileged browser pages, such as "about:debugging", and the [addons.mozilla.org](https://addons.mozilla.org/) website. In Chrome, this includes internal pages, such as `chrome:extensions`, and the [chromewebstore.google.com](https://chromewebstore.google.com/) website. If the user clicks the beastify icon on one of these pages, the popup displays an error message. | ||
|
|
||
| ## What it shows ## | ||
|
|
||
| * write a browser action with a popup | ||
| * how to have different browser_action images based upon the theme | ||
| * give the popup style and behavior using CSS and JS | ||
| * inject a content script programmatically using `tabs.executeScript()` | ||
| * send a message from the main extension to a content script | ||
| * use web accessible resources to enable web pages to load packaged content | ||
| * reload web pages | ||
| In this eample, you see how to: | ||
|
|
||
| * Write an action (toolbar button) with a popup. | ||
| * Display action (toolbar button) icons based on the browser theme. | ||
| * Give a popup style and behavior using CSS and JavaScript. | ||
| * Inject a content script programmatically using `scripting.executeScript()`. | ||
| * Send a message from the main extension to a content script. | ||
| * Use web accessible resources to enable web pages to load packaged content. | ||
| * Reload web pages. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| { | ||
|
|
||
| "description": "Adds a browser action icon to the toolbar. Click the button to choose a beast. The active tab's body content is then replaced with a picture of the chosen beast. See https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Examples#beastify", | ||
| "manifest_version": 2, | ||
| "manifest_version": 3, | ||
| "name": "Beastify", | ||
| "version": "1.0", | ||
| "homepage_url": "https://github.com/mdn/webextensions-examples/tree/master/beastify", | ||
|
|
@@ -10,10 +10,20 @@ | |
| }, | ||
|
|
||
| "permissions": [ | ||
| "activeTab" | ||
| "activeTab", | ||
| "scripting" | ||
| ], | ||
|
|
||
| "browser_action": { | ||
| "browser_specific_settings": { | ||
| "gecko": { | ||
| "id": "[email protected]", | ||
| "data_collection_permissions": { | ||
| "required": ["none"] | ||
| } | ||
| } | ||
| }, | ||
|
|
||
| "action": { | ||
| "default_icon": "icons/beasts-32.png", | ||
| "theme_icons": [{ | ||
| "light": "icons/beasts-32-light.png", | ||
|
|
@@ -25,7 +35,10 @@ | |
| }, | ||
|
|
||
| "web_accessible_resources": [ | ||
| "beasts/*.jpg" | ||
| { | ||
| "resources": [ "beasts/*.jpg" ], | ||
| "matches": [ "*://*/*" ] | ||
| } | ||
| ] | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,16 @@ | ||
| # borderify | ||
|
|
||
| **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 mozilla.org web pages. | ||
|
|
||
| ## What it does | ||
|
|
||
| This extension just includes: | ||
| This extension includes a content script, "borderify.js", that is injected into any pages | ||
| under "mozilla.org/" or any of its subdomains. | ||
|
|
||
| * a content script, "borderify.js", that is injected into any pages | ||
| under "mozilla.org/" or any of its subdomains | ||
| **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 content script draws a border around the document.body. | ||
|
|
||
| ## What it shows | ||
|
|
||
| * how to inject content scripts declaratively using manifest.json | ||
| From this example, you see how to inject content scripts declaratively using manifest.json. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| /* | ||
| Just draw a border round the document.body. | ||
| Draw a border round the document.body. | ||
| */ | ||
| document.body.style.border = "5px solid red"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,23 @@ | ||
| { | ||
|
|
||
| "description": "Adds a solid red border to all webpages matching mozilla.org. See https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Examples#borderify", | ||
| "manifest_version": 2, | ||
| "manifest_version": 3, | ||
| "name": "Borderify", | ||
| "version": "1.0", | ||
| "homepage_url": "https://github.com/mdn/webextensions-examples/tree/master/borderify", | ||
| "icons": { | ||
| "48": "icons/border-48.png" | ||
| }, | ||
|
|
||
| "browser_specific_settings": { | ||
| "gecko": { | ||
| "id": "[email protected]", | ||
| "data_collection_permissions": { | ||
| "required": ["none"] | ||
| } | ||
| } | ||
| }, | ||
|
|
||
| "content_scripts": [ | ||
| { | ||
| "matches": ["*://*.mozilla.org/*"], | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revise to use async/await instead of Promise chains.