7

Instead of automatically following JavaScript redirects, can I force HtmlUnit to return the URL the JavaScript wants to redirect me to?

// context:

If there's 5 JavaScript redirects in a row, I can only see the URL of the page where it stopped - I can't view the 5 URLs it ran through.

Perhaps I can hook up the logger to a callback method to look for redirects? Not sure if this is possible, or how it would work..

1 Answer 1

7

You can do this by adding a WebWindowListener to the WebClient, and waiting for the webWindowContentChanged method to get called.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, I did this and it worked fine. Keep in mind that you're working with multiple threads (webWindowContentChanged method is called by different thread), and that if you have multiple redirects you may have to wait for each of them.

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.