Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The page you linked to uses a piece of Javascript that either triggers a bug in HtmlUnit (didn't find any open issue, though) or is just plain broken for non-Webkit browsers (page works fine in IE10, though).</p> <p>Somewhere in <a href="http://www.wwnorton.com/college/polisci/we-the-people8/shorter/ScriptResource.axd?d=MbaAqAahxi3YDYdaT925QiLtHLHAvOZRQla5c0b24vyov-s_NmaN35GrSancbN-o7j4MWzv8triPZWBoWhCikubtoi3jDnL2qzjlivaOEByeT8R6w9pSGqIU8xlzao1u1OUnUB_6K1s1R8tBtZBWFQ2&amp;t=fffffffffd4601ba">this script</a>, some elements' <code>outerHTML</code> properties are set to <code>null</code> unless the browser is "not Safari"(*):</p> <pre><code>if (!$telerik.isSafari) { c.outerHTML = null; } if (!$telerik.isSafari) { a.outerHTML = null; } </code></pre> <p>(*) where "Safari" is revealed further downto actually mean "Webkit-based":</p> <pre><code>$telerik.isChrome = Sys.Browser.agent == Sys.Browser.Chrome; $telerik.isSafari4 = Sys.Browser.agent == Sys.Browser.WebKit &amp;&amp; Sys.Browser.version &gt;= 526; $telerik.isSafari3 = Sys.Browser.agent == Sys.Browser.WebKit &amp;&amp; Sys.Browser.version &lt; 526 &amp;&amp; Sys.Browser.version &gt; 500; $telerik.isSafari2 = Sys.Browser.agent == Sys.Browser.Safari; $telerik.isSafari = $telerik.isSafari2 || $telerik.isSafari3 || $telerik.isSafari4 || $telerik.isChrome; </code></pre> <p>I didn't bother to figure out what the obfuscated JS code wants to do with <code>outerHTML</code>, but it does fail a state check deep down in HtmlUnit's DOM manipulation code when executing the script:</p> <pre><code>java.lang.RuntimeException: Exception invoking setOuterHTML at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:669) ... Caused by: java.lang.IllegalStateException: Previous sibling for HtmlDivision[&lt;div style="..."&gt;] is null. at com.gargoylesoftware.htmlunit.html.DomNode.insertBefore(DomNode.java:1036) at com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.setOuterHTML(HTMLElement.java:1067) at ... </code></pre> <p>Telling HtmlUnit to identify as Chrome avoids both <code>outerHTML = null</code> assignments</p> <pre><code>WebClient client = new WebClient(BrowserVersion.CHROME); ... </code></pre> <p>and produces sensible looking output:</p> <pre><code>Chapter 15: The Federal Courts | We the People, 8e: W. W. Norton StudySpace W.W. Norton &amp; Company Colorblind Mode: On | Off W. W. NORTON HOME | HELP | CREDITS We the People, 8e: A W. W. Norton StudySpace ... </code></pre> <p>This was a fun thing to track down.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload