add firefox extension template

This commit is contained in:
2025-08-07 16:03:16 -05:00
parent 6cbb29fed1
commit 5df289ffcb
586 changed files with 13636 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
package webextension_polyfill.declarativenetrequest;
typedef IsRegexSupportedCallbackResultType = {
/**
Whether the given regex is supported
**/
var isSupported : Bool;
/**
Specifies the reason why the regular expression is not supported. Only provided if 'isSupported' is false.
Optional.
**/
@:optional
var reason : UnsupportedRegexReason;
};

View File

@@ -0,0 +1,21 @@
package webextension_polyfill.declarativenetrequest;
typedef IsRegexSupportedRegexOptionsType = {
/**
The regular expresson to check.
**/
var regex : String;
/**
Whether the 'regex' specified is case sensitive.
Optional.
**/
@:optional
var isCaseSensitive : Bool;
/**
Whether the 'regex' specified requires capturing. Capturing is only required for redirect rules which specify a
'regexSubstition' action.
Optional.
**/
@:optional
var requireCapturing : Bool;
};

View File

@@ -0,0 +1,18 @@
package webextension_polyfill.declarativenetrequest;
typedef MatchedRule = {
/**
A matching rule's ID.
**/
var ruleId : Float;
/**
ID of the Ruleset this rule belongs to.
**/
var rulesetId : String;
/**
ID of the extension, if this rule belongs to a different extension.
Optional.
**/
@:optional
var extensionId : String;
};

View File

@@ -0,0 +1,6 @@
package webextension_polyfill.declarativenetrequest;
/**
How the requested resource will be used. Comparable to the webRequest.ResourceType type.
**/
typedef ResourceType = String;

View File

@@ -0,0 +1,22 @@
package webextension_polyfill.declarativenetrequest;
typedef Rule = {
/**
An id which uniquely identifies a rule. Mandatory and should be >= 1.
**/
var id : Float;
/**
Rule priority. Defaults to 1. When specified, should be >= 1
Optional.
**/
@:optional
var priority : Float;
/**
The condition under which this rule is triggered.
**/
var condition : RuleConditionType;
/**
The action to take if this rule is matched.
**/
var action : RuleActionType;
};

View File

@@ -0,0 +1,33 @@
package webextension_polyfill.declarativenetrequest;
/**
Describes how the redirect should be performed. Only valid when type is 'redirect'.
**/
typedef RuleActionRedirectType = {
/**
Path relative to the extension directory. Should start with '/'.
Optional.
**/
@:optional
var extensionPath : String;
/**
Url transformations to perform.
Optional.
**/
@:optional
var transform : URLTransform;
/**
The redirect url. Redirects to JavaScript urls are not allowed.
Optional.
**/
@:optional
var url : String;
/**
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.
Optional.
**/
@:optional
var regexSubstitution : String;
};

View File

@@ -0,0 +1,18 @@
package webextension_polyfill.declarativenetrequest;
typedef RuleActionRequestHeadersItemType = {
/**
The name of the request header to be modified.
**/
var header : String;
/**
The operation to be performed on a header.
**/
var operation : String;
/**
The new value for the header. Must be specified for the 'append' and 'set' operations.
Optional.
**/
@:optional
var value : String;
};

View File

@@ -0,0 +1,18 @@
package webextension_polyfill.declarativenetrequest;
typedef RuleActionResponseHeadersItemType = {
/**
The name of the response header to be modified.
**/
var header : String;
/**
The operation to be performed on a header.
**/
var operation : String;
/**
The new value for the header. Must be specified for the 'append' and 'set' operations.
Optional.
**/
@:optional
var value : String;
};

View File

@@ -0,0 +1,26 @@
package webextension_polyfill.declarativenetrequest;
/**
The action to take if this rule is matched.
**/
typedef RuleActionType = {
var type : RuleActionTypeEnum;
/**
Describes how the redirect should be performed. Only valid when type is 'redirect'.
Optional.
**/
@:optional
var redirect : RuleActionRedirectType;
/**
The request headers to modify for the request. Only valid when type is 'modifyHeaders'.
Optional.
**/
@:optional
var requestHeaders : Array<RuleActionRequestHeadersItemType>;
/**
The response headers to modify for the request. Only valid when type is 'modifyHeaders'.
Optional.
**/
@:optional
var responseHeaders : Array<RuleActionResponseHeadersItemType>;
};

View File

@@ -0,0 +1,3 @@
package webextension_polyfill.declarativenetrequest;
typedef RuleActionTypeEnum = String;

View File

@@ -0,0 +1,7 @@
package webextension_polyfill.declarativenetrequest;
/**
Specifies whether the network request is first-party or third-party to the domain from which it originated. If omitted,
all requests are matched.
**/
typedef RuleConditionDomainTypeEnum = String;

View File

@@ -0,0 +1,104 @@
package webextension_polyfill.declarativenetrequest;
/**
The condition under which this rule is triggered.
**/
typedef RuleConditionType = {
/**
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.
Optional.
**/
@:optional
var urlFilter : String;
/**
Regular expression to match against the network request url. Only one of 'urlFilter' or 'regexFilter' can be specified.
Optional.
**/
@:optional
var regexFilter : String;
/**
Whether 'urlFilter' or 'regexFilter' is case-sensitive.
Optional.
**/
@:optional
var isUrlFilterCaseSensitive : Bool;
/**
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.
Optional.
**/
@:optional
var initiatorDomains : Array<String>;
/**
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'.
Optional.
**/
@:optional
var excludedInitiatorDomains : Array<String>;
/**
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.
Optional.
**/
@:optional
var requestDomains : Array<String>;
/**
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'.
Optional.
**/
@:optional
var excludedRequestDomains : Array<String>;
/**
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.
Optional.
**/
@:optional
var resourceTypes : Array<ResourceType>;
/**
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.
Optional.
**/
@:optional
var excludedResourceTypes : Array<ResourceType>;
/**
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'.'
Optional.
**/
@:optional
var requestMethods : Array<String>;
/**
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.
Optional.
**/
@:optional
var excludedRequestMethods : Array<String>;
/**
Specifies whether the network request is first-party or third-party to the domain from which it originated. If omitted,
all requests are matched.
Optional.
**/
@:optional
var domainType : RuleConditionDomainTypeEnum;
/**
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.
Optional.
**/
@:optional
var tabIds : Array<Float>;
/**
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.
Optional.
**/
@:optional
var excludedTabIds : Array<Float>;
};

View File

@@ -0,0 +1,76 @@
package webextension_polyfill.declarativenetrequest;
typedef Static = {
/**
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.
**/
function updateDynamicRules(options:UpdateDynamicRulesOptionsType):js.lib.Promise<ts.Undefined>;
/**
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.
**/
function updateSessionRules(options:UpdateSessionRulesOptionsType):js.lib.Promise<ts.Undefined>;
/**
Returns the ids for the current set of enabled static rulesets.
**/
function getEnabledRulesets():js.lib.Promise<Array<String>>;
/**
Returns the ids for the current set of enabled static rulesets.
**/
function updateEnabledRulesets(updateRulesetOptions:UpdateEnabledRulesetsUpdateRulesetOptionsType):js.lib.Promise<ts.Undefined>;
/**
Returns the remaining number of static rules an extension can enable
**/
function getAvailableStaticRuleCount():js.lib.Promise<Float>;
/**
Returns the current set of dynamic rules for the extension.
**/
function getDynamicRules():js.lib.Promise<Array<Rule>>;
/**
Returns the current set of session scoped rules for the extension.
**/
function getSessionRules():js.lib.Promise<Array<Rule>>;
/**
Checks if the given regular expression will be supported as a 'regexFilter' rule condition.
**/
function isRegexSupported(regexOptions:IsRegexSupportedRegexOptionsType):js.lib.Promise<IsRegexSupportedCallbackResultType>;
/**
Checks if any of the extension's declarativeNetRequest rules would match a hypothetical request.
**/
function testMatchOutcome(request:TestMatchOutcomeRequestType, ?options:TestMatchOutcomeOptionsType):js.lib.Promise<TestMatchOutcomeCallbackResultType>;
/**
Ruleset ID for the dynamic rules added by the extension.
**/
var DYNAMIC_RULESET_ID : String;
/**
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.
**/
var GUARANTEED_MINIMUM_STATIC_RULES : Float;
/**
The maximum number of static Rulesets an extension can specify as part of the rule_resources manifest key.
**/
var MAX_NUMBER_OF_STATIC_RULESETS : Float;
/**
The maximum number of static Rulesets an extension can enable at any one time.
**/
var MAX_NUMBER_OF_ENABLED_STATIC_RULESETS : Float;
/**
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.
**/
var MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES : Float;
/**
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.
**/
var MAX_NUMBER_OF_REGEX_RULES : Float;
/**
Ruleset ID for the session-scoped rules added by the extension.
**/
var SESSION_RULESET_ID : String;
};

View File

@@ -0,0 +1,8 @@
package webextension_polyfill.declarativenetrequest;
typedef TestMatchOutcomeCallbackResultType = {
/**
The rules (if any) that match the hypothetical request.
**/
var matchedRules : Array<MatchedRule>;
};

View File

@@ -0,0 +1,10 @@
package webextension_polyfill.declarativenetrequest;
typedef TestMatchOutcomeOptionsType = {
/**
Whether to account for rules from other installed extensions during rule evaluation.
Optional.
**/
@:optional
var includeOtherExtensions : Bool;
};

View File

@@ -0,0 +1,34 @@
package webextension_polyfill.declarativenetrequest;
/**
The details of the request to test.
**/
typedef TestMatchOutcomeRequestType = {
/**
The URL of the hypothetical request.
**/
var url : String;
/**
The initiator URL (if any) for the hypothetical request.
Optional.
**/
@:optional
var initiator : String;
/**
Standard HTTP method of the hypothetical request.
Optional.
**/
@:optional
var method : String;
/**
The resource type of the hypothetical request.
**/
var type : ResourceType;
/**
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.
**/
@:optional
var tabId : Float;
};

View File

@@ -0,0 +1,63 @@
package webextension_polyfill.declarativenetrequest;
/**
Describes the type of the Rule.action.redirect.transform property.
**/
typedef URLTransform = {
/**
The new scheme for the request.
Optional.
**/
@:optional
var scheme : URLTransformSchemeEnum;
/**
The new username for the request.
Optional.
**/
@:optional
var username : String;
/**
The new password for the request.
Optional.
**/
@:optional
var password : String;
/**
The new host name for the request.
Optional.
**/
@:optional
var host : String;
/**
The new port for the request. If empty, the existing port is cleared.
Optional.
**/
@:optional
var port : String;
/**
The new path for the request. If empty, the existing path is cleared.
Optional.
**/
@:optional
var path : String;
/**
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.
Optional.
**/
@:optional
var query : String;
/**
Add, remove or replace query key-value pairs. Cannot be specified if 'query' is specified.
Optional.
**/
@:optional
var queryTransform : URLTransformQueryTransformType;
/**
The new fragment for the request. Should be either empty, in which case the existing fragment is cleared; or should
begin with '#'.
Optional.
**/
@:optional
var fragment : String;
};

View File

@@ -0,0 +1,12 @@
package webextension_polyfill.declarativenetrequest;
typedef URLTransformQueryTransformAddOrReplaceParamsItemType = {
var key : String;
var value : String;
/**
If true, the query key is replaced only if it's already present. Otherwise, the key is also added if it's missing.
Optional.
**/
@:optional
var replaceOnly : Bool;
};

View File

@@ -0,0 +1,19 @@
package webextension_polyfill.declarativenetrequest;
/**
Add, remove or replace query key-value pairs. Cannot be specified if 'query' is specified.
**/
typedef URLTransformQueryTransformType = {
/**
The list of query keys to be removed.
Optional.
**/
@:optional
var removeParams : Array<String>;
/**
The list of query key-value pairs to be added or replaced.
Optional.
**/
@:optional
var addOrReplaceParams : Array<URLTransformQueryTransformAddOrReplaceParamsItemType>;
};

View File

@@ -0,0 +1,6 @@
package webextension_polyfill.declarativenetrequest;
/**
The new scheme for the request.
**/
typedef URLTransformSchemeEnum = String;

View File

@@ -0,0 +1,6 @@
package webextension_polyfill.declarativenetrequest;
/**
Describes the reason why a given regular expression isn't supported.
**/
typedef UnsupportedRegexReason = String;

View File

@@ -0,0 +1,16 @@
package webextension_polyfill.declarativenetrequest;
typedef UpdateDynamicRulesOptionsType = {
/**
IDs of the rules to remove. Any invalid IDs will be ignored.
Optional.
**/
@:optional
var removeRuleIds : Array<Float>;
/**
Rules to add.
Optional.
**/
@:optional
var addRules : Array<Rule>;
};

View File

@@ -0,0 +1,14 @@
package webextension_polyfill.declarativenetrequest;
typedef UpdateEnabledRulesetsUpdateRulesetOptionsType = {
/**
Optional.
**/
@:optional
var disableRulesetIds : Array<String>;
/**
Optional.
**/
@:optional
var enableRulesetIds : Array<String>;
};

View File

@@ -0,0 +1,16 @@
package webextension_polyfill.declarativenetrequest;
typedef UpdateSessionRulesOptionsType = {
/**
IDs of the rules to remove. Any invalid IDs will be ignored.
Optional.
**/
@:optional
var removeRuleIds : Array<Float>;
/**
Rules to add.
Optional.
**/
@:optional
var addRules : Array<Rule>;
};