Use custom functions to achieve more flexible functionality. So far, custom functions can be used in the following events: redirect request, modify the request headers, modify the response headers.
Custom functions are also limited by matching rules and exclusion rules. Only requests that meet the matching rules and do not satisfy the exclusion rule are processed by the custom function.
The priority of the custom function is not determined. It may be possible to customize the function earlier than the normal rule to the request, or it may be later. The order of execution of multiple custom functions is also variable.
When you can use normal rules to complete the case, please try to use the general rules, rather than custom function
Custom function writing does NOT include the function head and tail, including only the function body. which is:
For example:
The custom function passes the arguments val
and detail
, where detail
is the new parameter in version 2.3.0, see the description below. The return type varies depending on the rule type.
Pass the string with the full URL, if the function is not processed to return NULL or the original argument. For example, the following code will add a _test
to every request:
Since 4.0.3, return _header_editor_cancel_
will cancel this request, for example:
The incoming parameter is an array containing all header information in the following format: [{"name": "header name", "value": "header content"} ... ]
.
Because JS pass the Object by reference, the custom function does not need any return value, only need to modify the incoming parameters to take effect. For example, this code will add HE/2.0.0
to the end of User-Agent
:
Note: the browser requires that value must be String, i.e.
Since 2.3.0, the custom function adds the parameter detail
for the more precise control
This parameter is Object and is a read-only parameter. The structure is as follows:
Available resource type see here
You can use this to implement some advanced features, for example, the following code will only redirect images and videos from example.com to example.org:
All custom functions are run in the background page, so to debug custom functions, open the console of the background page
Chrome: Enable developer mode in chrome://extensions/
, then click the "Inspect views" - "background page" at the bottom of Header Editor
Firefox: Open about:debugging
, enable add-on debugging, click the "Debug" at the bottom of Header Editor