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
Editor: Mukul Purohit, Microsoft Corporation https://www.microsoft.com, [email protected]
9
9
Editor: Tomislav Jovanovic, Mozilla https://www.mozilla.org/, [email protected]
10
+
Editor: Oliver Dunk, Google https://www.google.com, [email protected]
10
11
Abstract: [Placeholder] Abstract.
11
12
Markup Shorthands: markdown yes
12
13
</pre>
@@ -27,11 +28,11 @@ An optional directory containing strings as defined in <a href="#localization">l
27
28
28
29
## Other files
29
30
30
-
An extension may also contain other files, such as those referenced in the <a href="#key-content_scripts">content_scripts</a> and <a href="#key-background">background</a> part of the <a href="#manifest">Manifest</a>.
31
+
An extension may also contain other files, such as those referenced in the [[#key-content_scripts]] and [[#key-background]] parts of the [=manifest=].
31
32
32
33
# Manifest
33
34
34
-
A WebExtension must have a manifest file at its root directory.
35
+
A WebExtension must have a <dfn>manifest</dfn> file at its root directory.
35
36
36
37
## Manifest file
37
38
@@ -112,7 +113,7 @@ This key may be present.
112
113
113
114
### Key `content_scripts`
114
115
115
-
This key may be present.
116
+
The <a href="#key-content_scripts">`content_scripts`</a> key is a [=list=] of items representing [=content scripts=] that should be registered.
116
117
117
118
### Key `content_security_policy`
118
119
@@ -154,6 +155,8 @@ Filenames beginning with an underscore (`_`) are reserved for use by user agent.
154
155
155
156
# Isolated worlds
156
157
158
+
<dfn>Worlds</dfn> are isolated JavaScript contexts with access to the same underlying DOM tree but their own set of wrappers around those DOM objects. Declarations in the global scope are also isolated.
159
+
157
160
# Unavailable APIs
158
161
159
162
# The `browser` global
@@ -172,6 +175,12 @@ Issue(62): Specify localization handling.
172
175
173
176
# Match patterns
174
177
178
+
A <dfn>match pattern</dfn> is a pattern used to match URLs. They are case-insensitive.
179
+
180
+
# Globs
181
+
182
+
A <dfn>glob</dfn> can be any [=string=]. It can contain any number of wildcards where `*` can match zero or more characters and `?` matches exactly one character.
183
+
175
184
# Concepts
176
185
177
186
## Uniqueness of extension IDs
@@ -190,7 +199,78 @@ Issue(62): Specify localization handling.
190
199
191
200
## Content scripts
192
201
193
-
### Isolated worlds
202
+
<dfn>Content scripts</dfn> represent a set of JS and CSS files that should be injected into matching pages loaded by the user agent. They are injected using the steps in [[#inject-a-content-script]].
203
+
204
+
### Key `matches`
205
+
206
+
A [=list=] of [=match patterns=] that are used to decide which pages the user agent injects the content script into. This key is required.
207
+
208
+
### Key `exclude_matches`
209
+
210
+
A [=list=] of [=match patterns=] that can be used to specify URLs where the content script should not run, even if the URL matches entries in [[#key-matches]] and (if specified) [[#key-include_globs]].
211
+
212
+
### Key `js`
213
+
214
+
A [=list=] of file paths, relative to the extension's package, that should be injected as scripts.
215
+
216
+
### Key `css`
217
+
218
+
A [=list=] of file paths, relative to the extension's package, that should be injected as stylesheets.
219
+
220
+
### Key `all_frames`
221
+
222
+
If `all_frames` is `true`, the content script must be injected into any subframes that match the other matching criteria for the content script. If `false`, content scripts will only be injected into top-level documents. Defaults to `false`.
223
+
224
+
### Key `match_about_blank`
225
+
226
+
If this is `true`, use the URL of the parent frame when matching a child frame whose document URL is `about:blank` or `about:srcdoc`. See also [[#determine-the-url-for-matching-a-document]]. Defaults to `false`.
227
+
228
+
### Key `match_origin_as_fallback`
229
+
230
+
If this is `true`, use fallbacks as described in [[#determine-the-url-for-matching-a-document]].
231
+
232
+
No path is available when the URL to match against falls back to an origin. Therefore, when set, the user agent may treat a [[#key-matches]] with a path other than `/*` as an error.
233
+
234
+
Defaults to `false`.
235
+
236
+
### Key `run_at`
237
+
238
+
Specifies when the content script should be injected. Valid values are defined by the {{RunAt}} enum.
239
+
240
+
### Key `include_globs`
241
+
242
+
A list of [=globs=] that a document should match. A document matches if the URL matches both the [[#key-matches]] field and the [[#key-include_globs]] field.
243
+
244
+
### Key `exclude_globs`
245
+
246
+
A [=list=] of [=globs=] that can be used to specify URLs where the content script should not run, even if the URL matches entries in [[#key-matches]] and (if specified) [[#key-include_globs]].
247
+
248
+
### Key `world`
249
+
250
+
The [=world=] any JavaScript scripts should be injected into. Defaults to `ISOLATED`. Valid values are defined by the {{ExecutionWorld}} enum.
251
+
252
+
### <dfn>RunAt</dfn> enum
253
+
254
+
<pre class="idl">
255
+
enum RunAt {
256
+
"document_start",
257
+
"document_end",
258
+
"document_idle"
259
+
};
260
+
</pre>
261
+
262
+
The {{RunAt}} enum represents when a content script should be injected.
263
+
264
+
### <dfn>ExecutionWorld</dfn> enum
265
+
266
+
<pre class="idl">
267
+
enum ExecutionWorld {
268
+
"ISOLATED",
269
+
"MAIN"
270
+
};
271
+
</pre>
272
+
273
+
The {{ExecutionWorld}} enum represents a JavaScript [=world=].
194
274
195
275
## Extension pages
196
276
@@ -203,3 +283,51 @@ Issue(62): Specify localization handling.
203
283
## Current behavior of cookie partitioning
204
284
205
285
# Version number handling
286
+
287
+
# Algorithms
288
+
289
+
## Determine the URL for matching a document
290
+
291
+
To determine the URL to use for matching a document, given the document, `match_origin_as_fallback` and `match_about_blank`:
292
+
293
+
1. Let |url| be the document's URL.
294
+
1. If the [=scheme=] of |url| is `http`, `https` or `file`:
295
+
1. Return |url|.
296
+
1. If the [=scheme=] of |url| is `blob`, `data` or `filesystem`, or if |url| is `about:blank` or `about:srcdoc`:
297
+
1. If `match_origin_as_fallback` is set to `true`:
298
+
1. If the document's origin is a [=tuple origin=]:
299
+
1. Let |document-origin| be the <a href="https://html.spec.whatwg.org/#ascii-serialisation-of-an-origin">serialization</a> of the document's origin.
300
+
1. If the [=scheme=] of |document-origin| is `http`, `https` or `file`:
301
+
1. Return |document-origin|.
302
+
1. Else, return null.
303
+
1. Note: If not a [=tuple origin=], the document’s origin is an [=opaque origin=].
304
+
1. Let |precursor-origin| be the <a href="https://html.spec.whatwg.org/#ascii-serialisation-of-an-origin">serialization</a> of the document’s precursor origin, if any.
305
+
306
+
Issue: "precursor origin" concept needs to be specified. It is not in the HTML spec at the moment. At least Chrome and Firefox recognize the concept, see e.g. <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1715167">https://bugzilla.mozilla.org/show_bug.cgi?id=1715167</a>.
307
+
1. If the [=scheme=] of |precursor-origin| is `http`, `https` or `file`:
308
+
1. Return |precursor-origin|.
309
+
1. Else, return null.
310
+
1. Else, if `match_about_blank` is set to `true`:
311
+
1. If |url| is `about:blank` or `about:srcdoc`:
312
+
1. Let |opener| be the active document of document’s [=opener browsing context=].
313
+
1. If all of the following conditions are true:
314
+
- |opener| is not null
315
+
- |opener|’s origin is still the same as the document’s [=opener origin at creation=]
316
+
- The algorithm has not been repeated for |opener| yet.
317
+
318
+
Then repeat the algorithm for |opener|.
319
+
1. Return null.
320
+
321
+
## Inject a content script
322
+
323
+
Issue: If the same extension specifies the same script twice, what should happen? ([bug](https://crbug.com/324096753))
324
+
325
+
To determine if a content script should be injected in a document:
326
+
327
+
1. Let |url| be the result of running [[#determine-the-url-for-matching-a-document]].
328
+
1. If the extension does not have access to |url|, return.
329
+
1. If |url| is not matched by a match pattern in `matches`, return.
330
+
1. If `include_globs` is present and |url| is not matched by any glob pattern, return.
331
+
1. If |url| matches an entry in `exclude_matches` or `exclude_globs`, return.
332
+
1. If this is a child frame, and `all_frames` is not `true`, return.
333
+
1. Otherwise, inject the content script. This should be done based on the `run_at` setting.
0 commit comments