summaryrefslogtreecommitdiffstats
path: root/toolkit/components/extensions/schemas/scripting.json
blob: 75003620cc6f6d233e6df556fb12a1c49f7f7f75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
[
  {
    "namespace": "manifest",
    "types": [
      {
        "$extend": "OptionalPermissionNoPrompt",
        "choices": [
          {
            "type": "string",
            "enum": ["scripting"]
          }
        ]
      }
    ]
  },
  {
    "namespace": "scripting",
    "description": "Use the scripting API to execute script in different contexts.",
    "permissions": ["scripting"],
    "types": [
      {
        "id": "ScriptInjection",
        "type": "object",
        "description": "Details of a script injection",
        "properties": {
          "args": {
            "type": "array",
            "optional": true,
            "description": "The arguments to curry into a provided function. This is only valid if the <code>func</code> parameter is specified. These arguments must be JSON-serializable.",
            "items": { "type": "any" }
          },
          "files": {
            "type": "array",
            "optional": true,
            "description": "The path of the JS files to inject, relative to the extension's root directory. Exactly one of <code>files</code> and <code>func</code> must be specified.",
            "minItems": 1,
            "items": { "type": "string" }
          },
          "func": {
            "type": "function",
            "optional": true,
            "description": "A JavaScript function to inject. This function will be serialized, and then deserialized for injection. This means that any bound parameters and execution context will be lost. Exactly one of <code>files</code> and <code>func</code> must be specified."
          },
          "target": {
            "$ref": "InjectionTarget",
            "description": "Details specifying the target into which to inject the script."
          },
          "world": {
            "$ref": "ExecutionWorld",
            "optional": true
          },
          "injectImmediately": {
            "type": "boolean",
            "optional": true,
            "description": "Whether the injection should be triggered in the target as soon as possible (but not necessarily prior to page load)."
          }
        }
      },
      {
        "id": "InjectionResult",
        "type": "object",
        "description": "Result of a script injection.",
        "properties": {
          "frameId": {
            "type": "integer",
            "description": "The frame ID associated with the injection."
          },
          "result": {
            "type": "any",
            "optional": true,
            "description": "The result of the script execution."
          },
          "error": {
            "type": "any",
            "optional": true,
            "description": "The error property is set when the script execution failed. The value is typically an (Error) object with a message property, but could be any value (including primitives and undefined) if the script threw or rejected with such a value."
          }
        }
      },
      {
        "id": "InjectionTarget",
        "type": "object",
        "properties": {
          "frameIds": {
            "type": "array",
            "optional": true,
            "description": "The IDs of specific frames to inject into.",
            "items": { "type": "number" }
          },
          "allFrames": {
            "type": "boolean",
            "optional": true,
            "description": "Whether the script should inject into all frames within the tab. Defaults to false. This must not be true if <code>frameIds</code> is specified."
          },
          "tabId": {
            "type": "number",
            "description": "The ID of the tab into which to inject."
          }
        }
      },
      {
        "id": "CSSInjection",
        "type": "object",
        "properties": {
          "css": {
            "type": "string",
            "optional": true,
            "description": "A string containing the CSS to inject. Exactly one of <code>files</code> and <code>css</code> must be specified."
          },
          "files": {
            "type": "array",
            "optional": true,
            "description": "The path of the CSS files to inject, relative to the extension's root directory. Exactly one of <code>files</code> and <code>css</code> must be specified.",
            "minItems": 1,
            "items": { "type": "string" }
          },
          "origin": {
            "type": "string",
            "optional": true,
            "enum": ["USER", "AUTHOR"],
            "default": "AUTHOR",
            "description": "The style origin for the injection. Defaults to <code>'AUTHOR'</code>."
          },
          "target": {
            "$ref": "InjectionTarget",
            "description": "Details specifying the target into which to inject the CSS."
          }
        }
      },
      {
        "id": "ContentScriptFilter",
        "type": "object",
        "properties": {
          "ids": {
            "type": "array",
            "optional": true,
            "description": "The IDs of specific scripts to retrieve with <code>getRegisteredContentScripts()</code> or to unregister with <code>unregisterContentScripts()</code>.",
            "items": { "type": "string" }
          }
        }
      },
      {
        "id": "ExecutionWorld",
        "type": "string",
        "enum": ["ISOLATED"],
        "description": "The JavaScript world for a script to execute within. We currently only support the <code>'ISOLATED'</code> world."
      },
      {
        "id": "RegisteredContentScript",
        "type": "object",
        "properties": {
          "allFrames": {
            "type": "boolean",
            "optional": true,
            "description": "If specified true, it will inject into all frames, even if the frame is not the top-most frame in the tab. Each frame is checked independently for URL requirements; it will not inject into child frames if the URL requirements are not met. Defaults to false, meaning that only the top frame is matched."
          },
          "excludeMatches": {
            "type": "array",
            "optional": true,
            "description": "Excludes pages that this content script would otherwise be injected into.",
            "items": { "type": "string" }
          },
          "id": {
            "type": "string",
            "description": "The id of the content script, specified in the API call."
          },
          "js": {
            "type": "array",
            "optional": true,
            "description": "The list of JavaScript files to be injected into matching pages. These are injected in the order they appear in this array.",
            "items": { "$ref": "manifest.ExtensionURL" }
          },
          "matches": {
            "type": "array",
            "optional": true,
            "description": "Specifies which pages this content script will be injected into. Must be specified for <code>registerContentScripts()</code>.",
            "items": { "type": "string" }
          },
          "runAt": {
            "$ref": "extensionTypes.RunAt",
            "optional": true,
            "description": "Specifies when JavaScript files are injected into the web page. The preferred and default value is <code>document_idle</code>."
          },
          "persistAcrossSessions": {
            "type": "boolean",
            "optional": true,
            "default": true,
            "description": "Specifies if this content script will persist into future sessions. Defaults to true."
          },
          "css": {
            "type": "array",
            "optional": true,
            "description": "The list of CSS files to be injected into matching pages. These are injected in the order they appear in this array.",
            "items": { "$ref": "manifest.ExtensionURL" }
          }
        }
      }
    ],
    "functions": [
      {
        "name": "executeScript",
        "type": "function",
        "description": "Injects a script into a target context. The script will be run at <code>document_idle</code>.",
        "async": "callback",
        "parameters": [
          {
            "name": "injection",
            "$ref": "ScriptInjection",
            "description": "The details of the script which to inject."
          },
          {
            "name": "callback",
            "type": "function",
            "description": "Invoked upon completion of the injection. The resulting array contains the result of execution for each frame where the injection succeeded.",
            "parameters": [
              {
                "name": "results",
                "type": "array",
                "items": { "$ref": "InjectionResult" }
              }
            ]
          }
        ]
      },
      {
        "name": "insertCSS",
        "type": "function",
        "description": "Inserts a CSS stylesheet into a target context. If multiple frames are specified, unsuccessful injections are ignored.",
        "async": "callback",
        "parameters": [
          {
            "name": "injection",
            "$ref": "CSSInjection",
            "description": "The details of the styles to insert."
          },
          {
            "name": "callback",
            "type": "function",
            "description": "Invoked upon completion of the injection.",
            "parameters": []
          }
        ]
      },
      {
        "name": "removeCSS",
        "type": "function",
        "description": "Removes a CSS stylesheet that was previously inserted by this extension from a target context.",
        "async": "callback",
        "parameters": [
          {
            "name": "injection",
            "$ref": "CSSInjection",
            "description": "The details of the styles to remove. Note that the <code>css</code>, <code>files</code>, and <code>origin</code> properties must exactly match the stylesheet inserted through <code>insertCSS</code>. Attempting to remove a non-existent stylesheet is a no-op."
          },
          {
            "name": "callback",
            "type": "function",
            "description": "Invoked upon completion of the injection.",
            "parameters": []
          }
        ]
      },
      {
        "name": "registerContentScripts",
        "type": "function",
        "description": "Registers one or more content scripts for this extension.",
        "async": "callback",
        "parameters": [
          {
            "name": "scripts",
            "type": "array",
            "description": "Contains a list of scripts to be registered. If there are errors during script parsing/file validation, or if the IDs specified already exist, then no scripts are registered.",
            "items": { "$ref": "RegisteredContentScript" }
          },
          {
            "name": "callback",
            "type": "function",
            "description": "Invoked upon completion of the registration.",
            "parameters": []
          }
        ]
      },
      {
        "name": "getRegisteredContentScripts",
        "type": "function",
        "description": "Returns all dynamically registered content scripts for this extension that match the given filter.",
        "async": "callback",
        "parameters": [
          {
            "name": "filter",
            "$ref": "ContentScriptFilter",
            "optional": true,
            "description": "An object to filter the extension's dynamically registered scripts."
          },
          {
            "name": "callback",
            "type": "function",
            "description": "The resulting array contains the registered content scripts.",
            "parameters": [
              {
                "name": "scripts",
                "type": "array",
                "items": { "$ref": "RegisteredContentScript" }
              }
            ]
          }
        ]
      },
      {
        "name": "unregisterContentScripts",
        "type": "function",
        "description": "Unregisters one or more content scripts for this extension.",
        "async": "callback",
        "parameters": [
          {
            "name": "filter",
            "$ref": "ContentScriptFilter",
            "optional": true,
            "description": "If specified, only unregisters dynamic content scripts which match the filter. Otherwise, all of the extension's dynamic content scripts are unregistered."
          },
          {
            "name": "callback",
            "type": "function",
            "description": "Invoked upon completion of the unregistration.",
            "parameters": []
          }
        ]
      },
      {
        "name": "updateContentScripts",
        "type": "function",
        "description": "Updates one or more content scripts for this extension.",
        "async": "callback",
        "parameters": [
          {
            "name": "scripts",
            "type": "array",
            "description": "Contains a list of scripts to be updated. If there are errors during script parsing/file validation, or if the IDs specified do not already exist, then no scripts are updated.",
            "items": {
              "type": "object",
              "$import": "RegisteredContentScript",
              "properties": {
                "persistAcrossSessions": {
                  "type": "boolean",
                  "optional": true,
                  "description": "Specifies if this content script will persist into future sessions."
                }
              }
            }
          },
          {
            "name": "callback",
            "type": "function",
            "description": "Invoked when scripts have been updated.",
            "parameters": []
          }
        ]
      }
    ]
  }
]