|
30 | 30 |
|
31 | 31 | <section name="Enable/Disable JavaScript support">
|
32 | 32 | <p>
|
33 |
| - JavaScript support is enabled per default like in real browsers. |
| 33 | + The JavaScript support is enabled per default like in real browsers. |
34 | 34 | </p>
|
| 35 | + |
| 36 | + <subsection name="Handling of JavaScript errors"> |
35 | 37 | <p>
|
36 |
| - <s>But:</s> There is one major difference - in the default configuration HtmlUnit will |
| 38 | + <strong>But:</strong> There is one major difference compared to real browsers - in |
| 39 | + the default configuration HtmlUnit will |
37 | 40 | stop JavaScript execution if an unhandled JavaScript error occurs. This is done
|
38 | 41 | because HtmlUnit was initially designed for testing where fail early is
|
39 | 42 | a good practice.<br></br>
|
40 | 43 | You can change this to silently (HtmlUnit will still log the exceptions)
|
41 |
| - ignore them (like in real browsers) by setting |
| 44 | + ignore the JavaScript exceptions (like in real browsers) by setting |
42 | 45 | the option throwExceptionOnScriptError to false.
|
43 | 46 | </p>
|
44 | 47 | <source><![CDATA[
|
45 | 48 | final WebClient webClient = new WebClient();
|
46 | 49 | webClient.getOptions.setThrowExceptionOnScriptError(false);
|
47 | 50 | ]]></source>
|
| 51 | + </subsection> |
48 | 52 |
|
| 53 | + <subsection name="Completely disable the JavaScript support"> |
49 | 54 | <p>
|
50 | 55 | For some use cases it might be helpful to completely disable the JavaScript support
|
51 |
| - (e.g. for better performance). |
| 56 | + (e.g. for better performance and less memory usage). |
52 | 57 | HtmlUnit offers two way to do this; you can completely disable JavaScript or only
|
53 | 58 | temporary.<br></br>
|
54 | 59 | To disable the JavaScript support (without the possibility to enable it for the WebClient
|
|
58 | 63 | <source><![CDATA[
|
59 | 64 | WebClient webClient = new WebClient(BrowserVersion.FIREFOX, false, null, -1);
|
60 | 65 | ]]></source>
|
| 66 | + </subsection> |
| 67 | + |
| 68 | + <subsection name="Temporary disable the JavaScript support"> |
61 | 69 | <p>
|
62 |
| - By using the WebClientOptions it is possible to disable and re-enable the JavaScript support |
63 |
| - at any time for a given client. Doing this will only stop executing the script tags |
64 |
| - and triggering any event listeners. |
| 70 | + By using the WebClientOptions it is possible to disable JavaScript support for a specific client |
| 71 | + at any time and enable it again later. |
| 72 | + However, this only disables the execution of the script tags and the triggering of event listeners. |
| 73 | + However, the JavaScript objects will still be created. |
65 | 74 | </p>
|
66 | 75 | <source><![CDATA[
|
67 | 76 | final WebClient webClient = new WebClient(BrowserVersion.FIREFOX);
|
68 | 77 | webClient.getOptions.setJavaScriptEnabled(false);
|
69 | 78 | ....
|
70 | 79 | webClient.getOptions.setJavaScriptEnabled(true);
|
71 | 80 | ]]></source>
|
| 81 | + </subsection> |
72 | 82 | </section>
|
73 | 83 |
|
74 | 84 | <section name="Example: using Document.write()">
|
|
0 commit comments