You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To test out the completed extension that you are building in this tutorial, download the [source code](https://github.com/MicrosoftEdge/MicrosoftEdge-Extensions-Demos/tree/master/extension-getting-started-part1/part1).<!-- changing master to main doesn't work 5/19/2022 -->
26
+
To test out the completed extension that you are building in this tutorial, download the source code from the [MicrosoftEdge-Extensions-Demos repo > extension-getting-started-part1](https://github.com/MicrosoftEdge/MicrosoftEdge-Extensions-Demos/tree/master/extension-getting-started-part1/part1).<!-- changing master to main doesn't work 5/19/2022 --> The source code has been updated from Manifest V2 to Manifest V3.
Every extension package must have a `manifest.json` file at the root. The manifest provides details of your extension, the extension package version, the extension name and description, and so on.
33
33
34
-
The following code snippet outlines the basic information needed in your `manifest.json` file.
34
+
The following code outlines the basic information needed in your `manifest.json` file:
35
+
36
+
#### [Manifest V2](#tab/v2)
35
37
36
38
```json
37
39
{
@@ -42,6 +44,19 @@ The following code snippet outlines the basic information needed in your `manife
42
44
}
43
45
```
44
46
47
+
#### [Manifest V3](#tab/v3)
48
+
49
+
```json
50
+
{
51
+
"name": "NASA picture of the day viewer",
52
+
"version": "0.0.0.1",
53
+
"manifest_version": 3,
54
+
"description": "An extension to display the NASA picture of the day."
* We recommend using `PNG` format, but you can also use `BMP`, `GIF`, `ICO` or `JPEG` formats.
55
70
* We recommend using images that are 128 x 128 px, which are resized by the browser if necessary.
56
71
57
-
The directories of your project should be similar to the following structure.
72
+
The directories of your project should be similar to the following structure:
58
73
59
74
```shell
60
75
└── part1
@@ -66,7 +81,9 @@ The directories of your project should be similar to the following structure.
66
81
└── nasapod128x128.png
67
82
```
68
83
69
-
Next, add the icons to the `manifest.json` file. Update your `manifest.json` file with the icons information so that it matches the following code snippet. The `png` files listed in the following code are available in the download file mentioned earlier in this article.
84
+
Next, add the icons to the `manifest.json` file. Update your `manifest.json` file with the icons information so that it matches the following code. The `png` files listed in the following code are available in the download file mentioned earlier in this article.
85
+
86
+
#### [Manifest V2](#tab/v2)
70
87
71
88
```json
72
89
{
@@ -83,13 +100,32 @@ Next, add the icons to the `manifest.json` file. Update your `manifest.json` fil
83
100
}
84
101
```
85
102
103
+
#### [Manifest V3](#tab/v3)
104
+
105
+
```json
106
+
{
107
+
"name": "NASA picture of the day viewer",
108
+
"version": "0.0.0.1",
109
+
"manifest_version": 3,
110
+
"description": "An extension to display the NASA picture of the day.",
Now, create a `HTML` file to run when the user launches your extension. Create the HTML file named `popup.html` in a directory named `popup`. When users select the icon to launch the extension, `popup/popup.html` is displayed as a modal dialog.
91
127
92
-
Add the code from the following code snippet to `popup.html` to display the stars image.
128
+
Add the code from the following listing to `popup.html` to display the stars image:
93
129
94
130
```html
95
131
<htmllang="en">
@@ -105,7 +141,7 @@ Add the code from the following code snippet to `popup.html` to display the star
105
141
</html>
106
142
```
107
143
108
-
Ensure that you add the image file `images/stars.jpeg` to the images folder. The directories of your project should be similar to the following structure.
144
+
Ensure that you add the image file `images/stars.jpeg` to the images folder. The directories of your project should be similar to the following structure:
109
145
110
146
```shell
111
147
└── part1
@@ -121,7 +157,9 @@ Ensure that you add the image file `images/stars.jpeg` to the images folder. Th
121
157
└── popup.html
122
158
```
123
159
124
-
Finally, ensure you register the pop-up in `manifest.json` under `browser_action`, as shown in the following code snippet.
160
+
Finally, register the pop-up in `manifest.json` under `browser_action` (in Manifest V2) or under `action` (in Manifest V3), as shown in the following code:
161
+
162
+
#### [Manifest V2](#tab/v2)
125
163
126
164
```json
127
165
{
@@ -141,6 +179,28 @@ Finally, ensure you register the pop-up in `manifest.json` under `browser_action
141
179
}
142
180
```
143
181
182
+
#### [Manifest V3](#tab/v3)
183
+
184
+
```json
185
+
{
186
+
"name": "NASA picture of the day viewer",
187
+
"version": "0.0.0.1",
188
+
"manifest_version": 3,
189
+
"description": "An extension to display the NASA picture of the day.",
Copy file name to clipboardExpand all lines: microsoft-edge/extensions-chromium/getting-started/part2-content-scripts.md
+90-4Lines changed: 90 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,11 +5,11 @@ author: MSEdgeTeam
5
5
ms.author: msedgedevrel
6
6
ms.topic: conceptual
7
7
ms.prod: microsoft-edge
8
-
ms.date: 01/07/2021
8
+
ms.date: 06/16/2022
9
9
---
10
10
# Create an extension tutorial, part 2
11
11
12
-
[Completed extension package source for this part](https://github.com/MicrosoftEdge/MicrosoftEdge-Extensions-Demos/tree/master/extension-getting-started-part2/extension-getting-started-part2)<!-- changing master to main doesn't work 5/19/2022 -->
12
+
To see the completed extension package source for this part of the tutorial, go to [MicrosoftEdge-Extensions-Demos repo > extension-getting-started-part2](https://github.com/MicrosoftEdge/MicrosoftEdge-Extensions-Demos/tree/master/extension-getting-started-part2/extension-getting-started-part2).<!-- changing master to main doesn't work 5/19/2022 --> The source code has been updated from Manifest V2 to Manifest V3.
4. Make your `stars.jpeg` available from any browser tab
116
149
117
150
You're probably wondering why, when you pass the `images/stars.jpeg` must you use the `chrome.extension.getURL` chrome Extension API instead of just passing in the relative URL without the extra prefix like in the previous section. By the way, that extra prefix, returned by `getUrl` with the image attached looks something like the following.
118
151
@@ -124,18 +157,35 @@ The reason is that you're injecting the image using the `src` attribute of the `
124
157
125
158
Add another entry in the `manifest.json` file to declare that the image is available to all browser tabs. That entry is as follows (you should see it in the full `manifest.json` file below when you add the content script declaration coming up).
126
159
160
+
#### [Manifest V2](#tab/v2)
161
+
127
162
```json
128
163
"web_accessible_resources": [
129
164
"images/*.jpeg"
130
165
]
131
166
```
132
167
168
+
#### [Manifest V3](#tab/v3)
169
+
170
+
```json
171
+
"web_accessible_resources": [
172
+
{
173
+
"resources": ["images/*.jpeg"],
174
+
"matches": ["<all_urls>"]
175
+
}
176
+
]
177
+
```
178
+
179
+
---
180
+
133
181
You've now written the code in your `popup.js` file to send a message to the content page that is embedded on the current active tab page, but you haven't created and injected that content page. Do that now.
134
182
135
-
5. Update your manifest.json for content and web access
183
+
5. Update your `manifest.json` for content and web access
136
184
137
185
The updated `manifest.json` that includes the `content-scripts` and `web_accessible_resources` is as follows.
138
186
187
+
#### [Manifest V2](#tab/v2)
188
+
139
189
```json
140
190
{
141
191
"name": "NASA picture of the day viewer",
@@ -165,6 +215,42 @@ The updated `manifest.json` that includes the `content-scripts` and `web_accessi
165
215
}
166
216
```
167
217
218
+
#### [Manifest V3](#tab/v3)
219
+
220
+
```json
221
+
{
222
+
"name": "NASA picture of the day viewer",
223
+
"version": "0.0.0.1",
224
+
"manifest_version": 3,
225
+
"description": "An extension to display the NASA picture of the day.",
The section you added is `content_scripts`. The `matches` attribute is set to `<all_urls>`, which means that all files in `content_scripts` are injected into all browser tab pages when each tab is loaded. The allowed files types that can be injected are JavaScript and CSS. You also added `lib\jquery.min.js`. You're able to include that from the download mentioned at the top of the section.
169
255
170
256
6. Add jQuery and understanding the associated thread
0 commit comments