Skip to main content

Rule execution priority

KurocoEdge's rule execution priority is sorted descendingly. The rules execution sequence starts from the highest number to the lowest number.

The rule execution priority can be set in the rule editor page. Image from Gyazo

Rule action interactions

If there are multiple rule actions that modify the same elements, then the modification of the rule action that is executed last will take precedence over rule actions that ran earlier. Lower rule execution priority translates to higher rule action priority, as rules that run last will have the highest rule action change priority.

For most rule actions, the changes made by prior rule actions will be taken into account by rule actions that will run later.

info

Rule actions that affect HTTP Headers are executed in-place one after another. However actions that modify the HTTP Body (such as HTML editor or Text replace - see below) are not executed in a chain : the required changes from all body-modifying rules are computed beforehand, and apply once on the streamed body.

Exceptions

There are exception to the above rule action interactions, which will be explained more in detail for each action type.

HTML editor

HTML editor actions do not affect each other, therefore, changes made by prior HTML editor actions will not be taken into account for HTML editor actions that run later.

Consider the following scenario:

  • The following sentence is displayed on the webpage: "This is a dog."
  • Rule A with execution priority 10, HTML editor action that replaces the word "This" with "That".
  • Rule B with execution priority 5, HTML editor action that replaces the word "dog" with "cat".
  • Rule C with execution priority 1, HTML editor action that replaces the word "That" with "Those".
  • Rule D with execution prioirty 0, HTML editor action that replaces the word "dog" with "cow".

The final result will be "That is a cow".

In terms of execution priority, the above rules will run in the following sequence A → B → C → D.

  • Rule A will change "This" to "That"
  • Rule B will change "dog" to "cat"
  • Rule C will not modify anything as there is no "That" word in the original sentence
  • Rule D will change "dog" to "cow",

HTML editor action does not affect each other, both rule C and rule D will apply its rule to the original sentence of "This is a dog" and does not take into account of the changes made by either rule A or rule B.

The lowest execution priority event (executed last) will effectively have the highest change priority, as it is executed last, its changes will override all other prior actions that make changes to the same source.

info

HTML editor works by registering events that would happen when the specified DOM element is encountered in the streamed body.
If there are multiple events attached to the same element, modifying the same data (e.g. the same attribute of the element), then all events will take the original source as input, therefore, the result of previous events will never be the input of the next.

Text replace

Similar to HTML editor, multiple Text replace action does not affect each other. However, in the case where multiple Text replace actions specify the same source with a different result, then only changes from one of the Text replace action will be randomly applied.

Consider the following scenario:

  • The word "Values" is displayed on the webpage
  • There are 2 Text replace actions with the following settings:
    • Text replace action A with the condition to replace "Va" with "B". The expected result would be "Blues"
    • Text replace action B with the condition to replace "Val" with "H". The expected result would be "Hues"

Regardless of the execution priority, the changes from only one of Text replace action above will be be applied.
The result is random, and could be "Blues" or "Hues".

note

In practice, multiple Text replace actions that modify the same source would have Conditions specified for each of the Text replace action, so that only one of the Text replace action would be executed if their specified condition is met.

If the rules are set up in a way where multiple Text replace that modify the same source would be executed, you may notice that the modification from rule with the higher rule execution priority take precedence, however there is no guarantee to this behavior. This is especially true with partial source overlap - as described in the scenario above, where you may notice that the rule with the easier text replacement would apply regardless of rule priority.

"Easier text replacement" refers to the following:

  • Modifying "Values" to "Blues" (replacing "Va" with "B") is easier than modifying it to "Hues" (replacing "Val" with "H") because only 2 letters have to be replaced.
info

KurocoEdge uses Aho-Corasick algorithm for efficient mass replacement of text strings on a streamed source. This results in the streamed source being processed only once, the output of one replacement is never being fed as input for next replacement(s).


Support

If you have any other questions, please contact us or check out Our Discord Community.