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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
|
[
{
"namespace": "manifest",
"types": [
{
"$extend": "Permission",
"choices": [
{
"type": "string",
"enum": ["declarativeNetRequest"]
}
]
},
{
"$extend": "OptionalPermission",
"choices": [
{
"type": "string",
"enum": ["declarativeNetRequestFeedback"]
}
]
},
{
"$extend": "PermissionNoPrompt",
"choices": [
{
"type": "string",
"enum": ["declarativeNetRequestWithHostAccess"]
}
]
},
{
"$extend": "WebExtensionManifest",
"properties": {
"declarative_net_request": {
"type": "object",
"optional": true,
"additionalProperties": { "$ref": "UnrecognizedProperty" },
"properties": {
"rule_resources": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"additionalProperties": { "$ref": "UnrecognizedProperty" },
"properties": {
"id": {
"type": "string",
"pattern": "^[^_]",
"description": "A non-empty string uniquely identifying the ruleset. IDs beginning with '_' are reserved for internal use."
},
"enabled": {
"type": "boolean",
"description": "Whether the ruleset is enabled by default."
},
"path": {
"$ref": "manifest.ExtensionURL",
"description": "The path of the JSON ruleset relative to the extension directory."
}
}
}
}
}
}
}
}
]
},
{
"namespace": "declarativeNetRequest",
"description": "Use the declarativeNetRequest API to block or modify network requests by specifying declarative rules.",
"permissions": [
"declarativeNetRequest",
"declarativeNetRequestWithHostAccess"
],
"types": [
{
"id": "ResourceType",
"type": "string",
"description": "How the requested resource will be used. Comparable to the webRequest.ResourceType type.",
"enum": [
"main_frame",
"sub_frame",
"stylesheet",
"script",
"image",
"object",
"object_subrequest",
"xmlhttprequest",
"xslt",
"ping",
"beacon",
"xml_dtd",
"font",
"media",
"websocket",
"csp_report",
"imageset",
"web_manifest",
"speculative",
"other"
]
},
{
"id": "UnsupportedRegexReason",
"type": "string",
"description": "Describes the reason why a given regular expression isn't supported.",
"enum": ["syntaxError", "memoryLimitExceeded"]
},
{
"id": "MatchedRule",
"type": "object",
"properties": {
"ruleId": {
"type": "integer",
"description": "A matching rule's ID."
},
"rulesetId": {
"type": "string",
"description": "ID of the Ruleset this rule belongs to."
},
"extensionId": {
"type": "string",
"description": "ID of the extension, if this rule belongs to a different extension.",
"optional": true
}
}
},
{
"id": "URLTransform",
"type": "object",
"description": "Describes the type of the Rule.action.redirect.transform property.",
"properties": {
"scheme": {
"type": "string",
"optional": true,
"description": "The new scheme for the request.",
"enum": ["http", "https", "moz-extension"]
},
"username": {
"type": "string",
"optional": true,
"description": "The new username for the request."
},
"password": {
"type": "string",
"optional": true,
"description": "The new password for the request."
},
"host": {
"type": "string",
"optional": true,
"description": "The new host name for the request."
},
"port": {
"type": "string",
"optional": true,
"description": "The new port for the request. If empty, the existing port is cleared."
},
"path": {
"type": "string",
"optional": true,
"description": "The new path for the request. If empty, the existing path is cleared."
},
"query": {
"type": "string",
"optional": true,
"description": "The new query for the request. Should be either empty, in which case the existing query is cleared; or should begin with '?'. Cannot be specified if 'queryTransform' is specified."
},
"queryTransform": {
"type": "object",
"optional": true,
"description": "Add, remove or replace query key-value pairs. Cannot be specified if 'query' is specified.",
"properties": {
"removeParams": {
"type": "array",
"optional": true,
"description": "The list of query keys to be removed.",
"items": {
"type": "string"
}
},
"addOrReplaceParams": {
"type": "array",
"optional": true,
"description": "The list of query key-value pairs to be added or replaced.",
"items": {
"type": "object",
"properties": {
"key": {
"type": "string"
},
"value": {
"type": "string"
},
"replaceOnly": {
"type": "boolean",
"optional": true,
"description": "If true, the query key is replaced only if it's already present. Otherwise, the key is also added if it's missing.",
"default": false
}
}
}
}
}
},
"fragment": {
"type": "string",
"optional": true,
"description": "The new fragment for the request. Should be either empty, in which case the existing fragment is cleared; or should begin with '#'."
}
}
},
{
"id": "Rule",
"type": "object",
"properties": {
"id": {
"type": "integer",
"description": "An id which uniquely identifies a rule. Mandatory and should be >= 1.",
"minimum": 1
},
"priority": {
"type": "integer",
"optional": true,
"description": "Rule priority. Defaults to 1. When specified, should be >= 1",
"minimum": 1,
"default": 1
},
"condition": {
"type": "object",
"description": "The condition under which this rule is triggered.",
"properties": {
"urlFilter": {
"type": "string",
"optional": true,
"description": "TODO: link to doc explaining supported pattern. The pattern which is matched against the network request url. Only one of 'urlFilter' or 'regexFilter' can be specified."
},
"regexFilter": {
"type": "string",
"optional": true,
"description": "Regular expression to match against the network request url. Only one of 'urlFilter' or 'regexFilter' can be specified."
},
"isUrlFilterCaseSensitive": {
"type": "boolean",
"optional": true,
"description": "Whether 'urlFilter' or 'regexFilter' is case-sensitive."
},
"initiatorDomains": {
"type": "array",
"optional": true,
"description": "The rule will only match network requests originating from the list of 'initiatorDomains'. If the list is omitted, the rule is applied to requests from all domains.",
"minItems": 1,
"items": {
"type": "string",
"format": "canonicalDomain"
}
},
"excludedInitiatorDomains": {
"type": "array",
"optional": true,
"description": "The rule will not match network requests originating from the list of 'initiatorDomains'. If the list is empty or omitted, no domains are excluded. This takes precedence over 'initiatorDomains'.",
"items": {
"type": "string",
"format": "canonicalDomain"
}
},
"requestDomains": {
"type": "array",
"optional": true,
"description": "The rule will only match network requests when the domain matches one from the list of 'requestDomains'. If the list is omitted, the rule is applied to requests from all domains.",
"minItems": 1,
"items": {
"type": "string",
"format": "canonicalDomain"
}
},
"excludedRequestDomains": {
"type": "array",
"optional": true,
"description": "The rule will not match network requests when the domains matches one from the list of 'excludedRequestDomains'. If the list is empty or omitted, no domains are excluded. This takes precedence over 'requestDomains'.",
"items": {
"type": "string",
"format": "canonicalDomain"
}
},
"resourceTypes": {
"type": "array",
"optional": true,
"description": "List of resource types which the rule can match. When the rule action is 'allowAllRequests', this must be specified and may only contain 'main_frame' or 'sub_frame'. Cannot be specified if 'excludedResourceTypes' is specified. If neither of them is specified, all resource types except 'main_frame' are matched.",
"minItems": 1,
"items": {
"$ref": "ResourceType"
}
},
"excludedResourceTypes": {
"type": "array",
"optional": true,
"description": "List of resource types which the rule won't match. Cannot be specified if 'resourceTypes' is specified. If neither of them is specified, all resource types except 'main_frame' are matched.",
"items": {
"$ref": "ResourceType"
}
},
"requestMethods": {
"type": "array",
"optional": true,
"description": "List of HTTP request methods which the rule can match. Should be a lower-case method such as 'connect', 'delete', 'get', 'head', 'options', 'patch', 'post', 'put'.'",
"minItems": 1,
"items": {
"type": "string"
}
},
"excludedRequestMethods": {
"type": "array",
"optional": true,
"description": "List of request methods which the rule won't match. Cannot be specified if 'requestMethods' is specified. If neither of them is specified, all request methods are matched.",
"items": {
"type": "string"
}
},
"domainType": {
"type": "string",
"optional": true,
"description": "Specifies whether the network request is first-party or third-party to the domain from which it originated. If omitted, all requests are matched.",
"enum": ["firstParty", "thirdParty"]
},
"tabIds": {
"type": "array",
"optional": true,
"description": "List of tabIds which the rule should match. An ID of -1 matches requests which don't originate from a tab. Only supported for session-scoped rules.",
"minItems": 1,
"items": {
"type": "integer"
}
},
"excludedTabIds": {
"type": "array",
"optional": true,
"description": "List of tabIds which the rule should not match. An ID of -1 excludes requests which don't originate from a tab. Only supported for session-scoped rules.",
"items": {
"type": "integer"
}
}
}
},
"action": {
"type": "object",
"description": "The action to take if this rule is matched.",
"properties": {
"type": {
"type": "string",
"enum": [
"block",
"redirect",
"allow",
"upgradeScheme",
"modifyHeaders",
"allowAllRequests"
]
},
"redirect": {
"type": "object",
"optional": true,
"description": "Describes how the redirect should be performed. Only valid when type is 'redirect'.",
"properties": {
"extensionPath": {
"type": "string",
"optional": true,
"description": "Path relative to the extension directory. Should start with '/'."
},
"transform": {
"$ref": "URLTransform",
"optional": true,
"description": "Url transformations to perform."
},
"url": {
"type": "string",
"format": "url",
"optional": true,
"description": "The redirect url. Redirects to JavaScript urls are not allowed."
},
"regexSubstitution": {
"type": "string",
"optional": true,
"description": "Substitution pattern for rules which specify a 'regexFilter'. The first match of regexFilter within the url will be replaced with this pattern. Within regexSubstitution, backslash-escaped digits (\\1 to \\9) can be used to insert the corresponding capture groups. \\0 refers to the entire matching text."
}
}
},
"requestHeaders": {
"type": "array",
"optional": true,
"description": "The request headers to modify for the request. Only valid when type is 'modifyHeaders'.",
"minItems": 1,
"items": {
"type": "object",
"properties": {
"header": {
"type": "string",
"description": "The name of the request header to be modified."
},
"operation": {
"type": "string",
"description": "The operation to be performed on a header.",
"enum": ["append", "set", "remove"]
},
"value": {
"type": "string",
"optional": true,
"description": "The new value for the header. Must be specified for the 'append' and 'set' operations."
}
}
}
},
"responseHeaders": {
"type": "array",
"optional": true,
"description": "The response headers to modify for the request. Only valid when type is 'modifyHeaders'.",
"minItems": 1,
"items": {
"type": "object",
"properties": {
"header": {
"type": "string",
"description": "The name of the response header to be modified."
},
"operation": {
"type": "string",
"description": "The operation to be performed on a header.",
"enum": ["append", "set", "remove"]
},
"value": {
"type": "string",
"optional": true,
"description": "The new value for the header. Must be specified for the 'append' and 'set' operations."
}
}
}
}
}
}
}
}
],
"functions": [
{
"name": "updateDynamicRules",
"type": "function",
"description": "Modifies the current set of dynamic rules for the extension. The rules with IDs listed in options.removeRuleIds are first removed, and then the rules given in options.addRules are added. These rules are persisted across browser sessions and extension updates.",
"async": "callback",
"parameters": [
{
"name": "options",
"type": "object",
"properties": {
"removeRuleIds": {
"type": "array",
"optional": true,
"description": "IDs of the rules to remove. Any invalid IDs will be ignored.",
"items": {
"type": "integer"
}
},
"addRules": {
"type": "array",
"optional": true,
"description": "Rules to add.",
"items": {
"$ref": "Rule"
}
}
}
},
{
"name": "callback",
"type": "function",
"description": "Called when the dynamic rules have been updated",
"parameters": []
}
]
},
{
"name": "updateSessionRules",
"type": "function",
"description": "Modifies the current set of session scoped rules for the extension. The rules with IDs listed in options.removeRuleIds are first removed, and then the rules given in options.addRules are added. These rules are not persisted across sessions and are backed in memory.",
"async": "callback",
"parameters": [
{
"name": "options",
"type": "object",
"properties": {
"removeRuleIds": {
"type": "array",
"optional": true,
"description": "IDs of the rules to remove. Any invalid IDs will be ignored.",
"items": {
"type": "integer"
}
},
"addRules": {
"type": "array",
"optional": true,
"description": "Rules to add.",
"items": {
"$ref": "Rule"
}
}
}
},
{
"name": "callback",
"type": "function",
"description": "Called when the session rules have been updated",
"parameters": []
}
]
},
{
"name": "getEnabledRulesets",
"type": "function",
"description": "Returns the ids for the current set of enabled static rulesets.",
"async": "callback",
"parameters": [
{
"name": "callback",
"type": "function",
"parameters": [
{
"type": "array",
"name": "rulesetIds",
"items": { "type": "string" }
}
]
}
]
},
{
"name": "updateEnabledRulesets",
"type": "function",
"description": "Returns the ids for the current set of enabled static rulesets.",
"async": "callback",
"parameters": [
{
"name": "updateRulesetOptions",
"type": "object",
"properties": {
"disableRulesetIds": {
"type": "array",
"items": { "type": "string" },
"optional": true,
"default": []
},
"enableRulesetIds": {
"type": "array",
"items": { "type": "string" },
"optional": true,
"default": []
}
}
},
{
"name": "callback",
"type": "function",
"parameters": []
}
]
},
{
"name": "getAvailableStaticRuleCount",
"type": "function",
"description": "Returns the remaining number of static rules an extension can enable",
"async": "callback",
"parameters": [
{
"name": "callback",
"type": "function",
"parameters": [
{
"name": "count",
"type": "integer"
}
]
}
]
},
{
"name": "getDynamicRules",
"type": "function",
"description": "Returns the current set of dynamic rules for the extension.",
"async": "callback",
"parameters": [
{
"name": "callback",
"type": "function",
"parameters": [
{
"name": "dynamicRules",
"type": "array",
"items": {
"$ref": "Rule"
}
}
]
}
]
},
{
"name": "getSessionRules",
"type": "function",
"description": "Returns the current set of session scoped rules for the extension.",
"async": "callback",
"parameters": [
{
"name": "callback",
"type": "function",
"parameters": [
{
"name": "sessionRules",
"type": "array",
"items": {
"$ref": "Rule"
}
}
]
}
]
},
{
"name": "isRegexSupported",
"type": "function",
"description": "Checks if the given regular expression will be supported as a 'regexFilter' rule condition.",
"async": "callback",
"parameters": [
{
"name": "regexOptions",
"type": "object",
"properties": {
"regex": {
"type": "string",
"description": "The regular expresson to check."
},
"isCaseSensitive": {
"type": "boolean",
"optional": true,
"description": "Whether the 'regex' specified is case sensitive.",
"default": false
},
"requireCapturing": {
"type": "boolean",
"optional": true,
"description": "Whether the 'regex' specified requires capturing. Capturing is only required for redirect rules which specify a 'regexSubstition' action.",
"default": false
}
}
},
{
"name": "callback",
"type": "function",
"parameters": [
{
"name": "result",
"type": "object",
"properties": {
"isSupported": {
"type": "boolean",
"description": "Whether the given regex is supported"
},
"reason": {
"$ref": "UnsupportedRegexReason",
"optional": true,
"description": "Specifies the reason why the regular expression is not supported. Only provided if 'isSupported' is false."
}
}
}
]
}
]
},
{
"name": "testMatchOutcome",
"type": "function",
"description": "Checks if any of the extension's declarativeNetRequest rules would match a hypothetical request.",
"permissions": ["declarativeNetRequestFeedback"],
"async": "callback",
"parameters": [
{
"name": "request",
"type": "object",
"description": "The details of the request to test.",
"properties": {
"url": {
"type": "string",
"description": "The URL of the hypothetical request."
},
"initiator": {
"type": "string",
"description": "The initiator URL (if any) for the hypothetical request.",
"optional": true
},
"method": {
"type": "string",
"description": "Standard HTTP method of the hypothetical request.",
"optional": true,
"default": "get"
},
"type": {
"$ref": "ResourceType",
"description": "The resource type of the hypothetical request."
},
"tabId": {
"type": "integer",
"description": "The ID of the tab in which the hypothetical request takes place. Does not need to correspond to a real tab ID. Default is -1, meaning that the request isn't related to a tab.",
"optional": true,
"default": -1
}
}
},
{
"name": "options",
"type": "object",
"optional": true,
"properties": {
"includeOtherExtensions": {
"type": "boolean",
"description": "Whether to account for rules from other installed extensions during rule evaluation.",
"optional": true
}
}
},
{
"name": "callback",
"type": "function",
"description": "Called with the details of matched rules.",
"parameters": [
{
"name": "result",
"type": "object",
"properties": {
"matchedRules": {
"type": "array",
"description": "The rules (if any) that match the hypothetical request.",
"items": {
"$ref": "MatchedRule"
}
}
}
}
]
}
]
}
],
"properties": {
"DYNAMIC_RULESET_ID": {
"type": "string",
"value": "_dynamic",
"description": "Ruleset ID for the dynamic rules added by the extension."
},
"GUARANTEED_MINIMUM_STATIC_RULES": {
"type": "number",
"description": "The minimum number of static rules guaranteed to an extension across its enabled static rulesets. Any rules above this limit will count towards the global static rule limit."
},
"MAX_NUMBER_OF_STATIC_RULESETS": {
"type": "number",
"description": "The maximum number of static Rulesets an extension can specify as part of the rule_resources manifest key."
},
"MAX_NUMBER_OF_ENABLED_STATIC_RULESETS": {
"type": "number",
"description": "The maximum number of static Rulesets an extension can enable at any one time."
},
"MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES": {
"type": "number",
"description": "The maximum number of dynamic and session rules an extension can add. NOTE: in the Firefox we are enforcing this limit to the session and dynamic rules count separately, instead of enforcing it to the rules count for both combined as the Chrome implementation does."
},
"MAX_NUMBER_OF_REGEX_RULES": {
"type": "number",
"description": "The maximum number of regular expression rules that an extension can add. This limit is evaluated separately for the set of session rules, dynamic rules and those specified in the rule_resources file."
},
"SESSION_RULESET_ID": {
"type": "string",
"value": "_session",
"description": "Ruleset ID for the session-scoped rules added by the extension."
}
}
}
]
|