Java htmlunit cannot load javascript

What causes this error and how to fix it?

WebClient webClient = new WebClient(); HtmlPage page = webClient.getPage("http://stackoverflow.com"); 

Error message

May 25, 2013 10:34:12 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify WARNING: Outdated content type failed: "text / javascript". May 25, 2013 10:34:13 com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter runtimeError SEVERE: runtimeError: message = [Data needed to complete this operation is not yet available.] SourceName = [http: //ajax.googleapis. com / ajax / libs / jquery / 1.7.1 / jquery.min.js] line = [2] lineSource = [null] lineOffset = [0] May 25, 2013 10:34:15 com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify WARNING: Outdated content type failed: "text / javascript". May 25, 2013 10:34:16 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error WARNING: CSS error: 'cdn.sstatic.net/stackoverflow/all.css?v=1748204ca390' [1: 3230] Error in style rule . (Invalid token "!". Expected one of: ,, "inherit" ,,,,,,,,,,,,,,,,,,, "," / "," - ".) May 25, 2013 . 10:34:16 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler warning WARNING: CSS warning: 'cdn.sstatic.net/stackoverflow/all.css?v=1748204ca390' [1: 3230] Ignore the following declarations in this rule. 25 May 2013 10:34:16 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error WARNING: CSS error: 'cdn.sstatic.net/stackoverflow/all.css?v=1748204ca390' [1: 6341] Error in style rule. (Invalid token "!". Expected one of: ,, "inherit" ,,,,,,,,,,,,,,,,,,, "," / "," - ".) May 25, 2013 10:34:16 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler warning WARNING: CSS warning : 'cdn.sstatic.net/stackoverflow/all.css?v=1748204ca390' [1: 6341] Ignore the following declarations in this rule. May 25, 2013 10:34:16 am com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error WARNING: CSS error: 'cdn.sstatic.net/stackoverflow/all.css?v=1748204ca390' [1: 14777] Error in style rule . (Invalid token "!". Expected one of: ,, "inherit" ,,,,,,,,,,,,,,,,,,, "," / "," - ".) May 25, 2013 10:34:16 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler warning WARNING: CSS warning: 'cdn.sstatic.net/stackoverflow/all.css?v=1748204ca390' [1: 14777] Ignore the following declarations in this rule. May 2013 10:34:17 Error com.gargoylesoftware.htmlunit.DefaultCssErrorHandler WARNING: CSS error: 'cdn.sstatic.net/stackoverflow/all.css?v=1748204ca390' [1: 31657] Error in style rule. ( Invalid token "!". Expected one of: ,, "inherit" ,,,,,,,,,,,,,,,,,,, "," / "," - ".) May 25, 2013 10:34:17 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler warning WARNING: CSS warning: 'cdn.sstatic.net/stackoverflow/all.css?v=1748204ca390' [1: 31657] Ignore the following declarations in this rule. May 25, 2013 10:34:17 Error com.gargoylesoftware.htmlunit.DefaultCssErrorHandler WARNING: CSS error: 'cdn.sstatic.net/stackoverflow/all.css?v=1748204ca390' [1: 73253] Error in style rule. (Invalid token ":". Expected one of: ,, "inherit" ,,,,,,,,,,,,,,}, "," / "," - ".) May 25, 2013 10: 34:17 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler warning WARNING: CSS warning: 'cdn.sstatic.net/stackoverflow/all.css?v=1748204ca390' [1: 73253] Ignore the following declarations in this rule. May 25, 2013 . 10:34:17 Error com.gargoylesoftware.htmlunit.DefaultCssErrorHandler WARNING: CSS error: 'cdn.sstatic.net/stackoverflow/all.css?v=1748204ca390' [1: 112886] Error in expression. (Invalid token "# # ffffff ". Expected one of: ,,,, - ,, = ,,).). May 25, 2013 10:34:17 Error com.gargoylesoftware.htmlunit.DefaultCssErrorHandler WARNING: CSS error: 'cdn.sstatic.net /stackoverflow/all.css?v=1748204ca390 '[1: 112928] About error in style rule. (Invalid token "background". Expected one of :, "}", ";".) May 25, 2013 10:34:17 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler warning WARNING: CSS warning: 'cdn.sstatic.net/stackoverflow/all.css?v=1748204ca390' [1: 112928] Ignore the following declarations in this rule. May 25, 2013 10:34:19 com.gargoylesoftware.htmlunit.javascript.host.ActiveXObject jsConstructor WARNING. The automation server cannot create an object for "ShockwaveFlash.ShockwaveFlash.7". May 25, 2013 10:34:19 com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter runtimeError SEVERE: runtimeError: message = [Automation server cannot create an object for "ShockwaveFlash.ShockwaveFlash.7".] SourceName = [http: // www.google-analytics.com/ga.js] line = [25] lineSource = [null] lineOffset = [0] May 25, 2013 10:34:19 com.gargoylesoftware.htmlunit.javascript.host.ActiveXObject jsConstructor WARNING . The automation server cannot create an object for "ShockwaveFlash.ShockwaveFlash.6". May 25, 2013 10:34:19 com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter runtimeError SEVERE: runtimeError: message = [The automation server cannot create an object for "ShockwaveFlash.ShockwaveFlash.6".] SourceName = [http: // www.google-analytics.com/ga.js] line = [25] lineSource = [null] lineOffset = [0] May 25, 2013 10:34:19 com.gargoylesoftware.htmlunit.javascript.host.ActiveXObject jsConstructor WARNING . The automation server cannot create an object for "ShockwaveFlash.ShockwaveFlash". May 25, 2013 10:34:19 com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter runtimeError SEVERE: runtimeError: message = [Automation server cannot create an object for "ShockwaveFlash.ShockwaveFlash".] SourceName = [http: // www. google-analytics.com/ga.js] line = [25] lineSource = [null] lineOffset = [0] May 25, 2013 10:34:20 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify WARNING: Outdated content type failed : "application / x-javascript". May 25, 2013 10:34:21 org.apache.http.client.protocol.ResponseProcessCookies processCookies WARNING: Invalid cookie header: "Set-Cookie: azk-views =; Max-Age = 31536000000; Path = /; Expires = Sun, May 25, 2014 5:34:42 PM GMT. " Invalid max-age attribute: 31536000000 May 25, 2013 10:34:21 org.apache.http.client.protocol.ResponseProcessCookies processCookies WARNING: Invalid cookie header: "Set-Cookie: azk-events =; Max-Age = 2592000000; Path = /; Expires = Mon, 24 Jun 2013 17:34:42 GMT ". Invalid max-age attribute: 2592000000 May 25, 2013 10:34:21 org.apache.http.client.protocol.ResponseProcessCookies processCookies WARNING: Invalid cookie header: "Set-Cookie: azk-vote =; Max-Age = 2592000000; Path = /; Expires = Mon, 24 Jun 2013 17:34:42 GMT ". Invalid max-age attribute: 2592000000 May 25, 2013 10:34:21 com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl report WARNING: Outdated content type failed: "text / javascript". May 25, 2013 10:34:23 com.gargoylesoftware.htmlunit.javascript.background.JavaScriptJobManagerImpl runSingleJob SEVERE: job execution failed with unexpected RuntimeException: exception throws setInnerHTML

+5
source share
2 answers

These are not errors, they are warnings .

They are caused by the fact that the htmlUnit Mozillas Rhino JavaScript engine was unable to correctly interpret JavaScript code. (This is not as good as some of the other popular JS engines.)

You can turn off these warnings, like:

 public static void main(String[] args) throws Exception { // turn off htmlunit warnings java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(java.util.logging.Level.OFF); java.util.logging.Logger.getLogger("org.apache.http").setLevel(java.util.logging.Level.OFF); WebClient webClient = new WebClient(); HtmlPage page = webClient.getPage("http://stackoverflow.com"); System.out.println(page.getTitleText()); } 

Output:

 Stack Overflow 
+18
source

Set the inclusion of Javascript and CSS in the webClient browser as follows:

 webClient.getOptions().setJavaScriptEnabled(false); webClient.getOptions().setCssEnabled(false); 

You can ON / OFF with passint parameters true or false.

0
source

Source: https://habr.com/ru/post/1482765/