I'm testing HTMLUnit with a fingerprinting website and it returns has_lied_languages = true and js_fonts also contains no fonts which is probably the reason for has_lied_languages being true.
I have put the fingerprinting page here, if you access it by Google Chrome you will see that js_fonts has some fonts in front of it.
But if you access it with HtmlUnit, js_fonts is blank and has_lied_languages = false
try {
BrowserVersion bv = BrowserVersion.CHROME;
webClient = new WebClient(bv);
webClient.getOptions().setTimeout(900000);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.setCssErrorHandler(new SilentCssErrorHandler());
webClient.getCache().setMaxSize(0);
LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log",
"org.apache.commons.logging.impl.NoOpLog");
java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF);
java.util.logging.Logger.getLogger("org.apache.commons.httpclient").setLevel(Level.OFF);
java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter")
.setLevel(Level.OFF);
java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit.javascript.host.ActiveXObject")
.setLevel(Level.OFF);
java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument")
.setLevel(Level.OFF);
java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit.html.HtmlScript").setLevel(Level.OFF);
java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit.javascript.host.WindowProxy")
.setLevel(Level.OFF);
java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF);
java.util.logging.Logger.getLogger("org.apache").setLevel(Level.OFF);
HtmlPage htmlPage = webClient.getPage("http://45.33.94.30/test.html");
Thread.sleep(9000);
htmlPage.save(new File("result.html"));
webClient.close();
} catch (Exception e) {
e.printStackTrace();
}
As far as i can see this is because HtmlUnit is a headless browser. Instead of doing real page layouting we are doing some estimations. For your sample the offsetWidth property ignores the font face.
Testcase: com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement2Test.offsetWidth_spanWithDiffernetFonts()
Is there a way to simulate it? By manually setting a list of js_fonts?
I just tried the latest build and I see that has_lied_languages now returns false, but has_lied_browser returns true. The reason for this is ProductSub, I manually changed the getProductSub() in Navigator.java to what Google Chrome returns and that solved the issue.
getProductSub is now fixed
Last edit: RBRi 2017-10-15
Will close this, i guess we have fixed what is possible with a headless browser.