Module org.htmlunit
Class HtmxTwoZeroSevenScriptPreProcessor
java.lang.Object
org.htmlunit.javascript.preprocessor.HtmxTwoZeroSevenScriptPreProcessor
- All Implemented Interfaces:
ScriptPreProcessor
A
ScriptPreProcessor implementation that applies compatibility patches to
htmx 2.0.3 - 2.0.10 versions of the htmx JavaScript library.
This preprocessor rewrites certain ECMAScript syntax constructs (such as spread operator usage in array push and for-of loops over array copies) to equivalent ES5-compatible code. This is necessary because these features are not yet supported by the JavaScript engine htmlunit-corejs (Rhino).
The class can be chained with other ScriptPreProcessor instances via its constructor.
Supported patches include:
- Replacing
result.push(...toArray(...))withresult.push.apply(result, toArray(...)) - Replacing
result.push(...findAttributeTargets(...))withresult.push.apply(result, findAttributeTargets(...)) - Replacing
for (const preservedElt of [...pantry.children])withfor (const preservedElt of Array.from(pantry.children)) - Similar replacements for minified htmx scripts (e.g.,
htmx.min.js)
Usage Example:
try (WebClient webClient = new WebClient()) {
webClient.setScriptPreProcessor(new HtmxTwoZeroSevenScriptPreProcessor());
// use webClient as needed
}
- Author:
- Ronald Brill
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCtor.HtmxTwoZeroSevenScriptPreProcessor(ScriptPreProcessor nextScriptPreProcessor) Ctor. -
Method Summary
Modifier and TypeMethodDescriptionpreProcess(HtmlPage htmlPage, String sourceCode, String sourceName, int lineNumber, HtmlElement htmlElement) Pre process the specified source code in the context of the given page.
-
Constructor Details
-
HtmxTwoZeroSevenScriptPreProcessor
public HtmxTwoZeroSevenScriptPreProcessor()Ctor. -
HtmxTwoZeroSevenScriptPreProcessor
Ctor.- Parameters:
nextScriptPreProcessor- the nextScriptPreProcessor
-
-
Method Details
-
preProcess
public String preProcess(HtmlPage htmlPage, String sourceCode, String sourceName, int lineNumber, HtmlElement htmlElement) Pre process the specified source code in the context of the given page.- Specified by:
preProcessin interfaceScriptPreProcessor- Parameters:
htmlPage- the pagesourceCode- the code to executesourceName- a name for the chunk of code that is going to be executed (used in error messages)lineNumber- the line number of the source codehtmlElement- the HTML element that will act as the context- Returns:
- the source code after pre processing
-