1

HtmlUnit takes lot of time to execute javascript, i would like to know if its possible to make HtmlUnit not to load javascript from url regex filters.

1 Answer 1

2

Not exactly, you can't only disable javascript as a whole (probably you already know it):

final WebClient webClient = new WebClient();
webClient.getOptions().setJavascriptEnable(false);

but you can use a ScriptPreProcessor the javascript, and erase what you don't want:

webClient.setScriptPreProcessor(new ScriptPreProcessor() {

        @Override
        public String preProcess(HtmlPage htmlPage, String sourceCode, String sourceName, int lineNumber, HtmlElement htmlElement) {
            if (match...)
            return "";
        }
    });
Sign up to request clarification or add additional context in comments.

1 Comment

How would I do this when using HtmlUnitDriver? Ref. stackoverflow.com/questions/30303430/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.