JS Browserdetection fail and redirect
See original GitHub issuebased on JavaScript execution exeption question on Stackoverflow
HtmlUnit Version: 2.50.0
During getPage call of webpage flashscore.com, i got following exceptions
2021-07-07 08:46:05.408 WARN 4828 --- [nio-8080-exec-1] c.g.htmlunit.IncorrectnessListenerImpl : Obsolete content type encountered: 'text/javascript'.
2021-07-07 08:46:05.564 ERROR 4828 --- [nio-8080-exec-1] c.g.h.j.DefaultJavaScriptErrorListener : Error during JavaScript execution
com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot find function entries in object function Object() { [native code] }. (script in https://www.flashscore.com/unsupported/ from (31, 9) to (53, 10)#35)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:949) ~[htmlunit-2.50.0.jar:2.50.0]
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:598) ~[htmlunit-core-js-2.50.0.jar:na]
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:487) ~[htmlunit-core-js-2.50.0.jar:na]
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.callSecured(HtmlUnitContextFactory.java:353) ~[htmlunit-2.50.0.jar:2.50.0]
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:829) ~[htmlunit-2.50.0.jar:2.50.0]
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:805) ~[htmlunit-2.50.0.jar:2.50.0]
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:796) ~[htmlunit-2.50.0.jar:2.50.0]
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScript(HtmlPage.java:942) ~[htmlunit-2.50.0.jar:2.50.0]
at com.gargoylesoftware.htmlunit.html.ScriptElementSupport.executeInlineScriptIfNeeded(ScriptElementSupport.java:378) ~[htmlunit-2.50.0.jar:2.50.0]
I’ve tried with two different classes and problem still occur.
@PostMapping("/startScraping")
public ResponseEntity<FlashScraper> startScraping(@NonNull @RequestBody FlashScraper flashScraper) throws FailingHttpStatusCodeException, MalformedURLException, IOException {
logger.info("startScraping request incomming");
logger.info("Call URL: " + flashScraper.getScrapeUrl());
String url = "https://flashScore.com";
try (final WebClient webClient = new WebClient(BrowserVersion.BEST_SUPPORTED)) {
HtmlPage page = webClient.getPage(url);
webClient.waitForBackgroundJavaScript(3_000);
System.out.println();
System.out.println();
System.out.println("----------------");
System.out.println(page.asNormalizedText());
System.out.println("----------------");
}
return new ResponseEntity(flashScraper, HttpStatus.OK);
}
@PostMapping("/startScraping")
public ResponseEntity<FlashScraper> startScraping(@NonNull @RequestBody FlashScraper flashScraper) throws FailingHttpStatusCodeException, MalformedURLException, IOException {
logger.info("startScraping request incomming");
logger.info("Call URL: " + flashScraper.getScrapeUrl());
final WebClient webClient = new WebClient(BrowserVersion.BEST_SUPPORTED);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.waitForBackgroundJavaScriptStartingBefore(1000);
HtmlPage scrapePage = webClient.getPage(flashScraper.getScrapeUrl());
webClient.waitForBackgroundJavaScript(3000);
System.out.println(scrapePage.getByXPath("//*[@id=\"g_25_rwPxTVj1\"]"));
return new ResponseEntity(flashScraper, HttpStatus.OK);
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Browser version detect and redirect - javascript - Stack Overflow
Tried this and a few others from forums and I'm testing using IE8.0.6001.18702 and it's not redirecting <script type="text/javascript"> <!
Read more >Browser detection using the user agent - HTTP - MDN Web Docs
Browser detection using the user agent. Serving different Web pages or services to different browsers is usually a bad idea.
Read more >My JavaScript redirect is not working - MSDN
Hi,. I have simple JavaScript code that I use after handling transactions i.e. user making an entry ,etc. Basically, I grab the URL...
Read more >JS browser detect & page redirect
I'm trying to have a Javascript that detects the visitor's browser, ... var BrowserDetect = { init: function () { this.browser = this....
Read more >How to Detect Mobile Browsers with JavaScript - Stack Diary
The holy grail of browser detection is the navigator.UserAgent property. if (/Android|iPhone/i.test(navigator ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Looks like another error - this time
invalid property id (https://www.flashscore.com/res/_fs/build/loader.5714507.js#1)
And this js is a huge minimized javascript. At least this uses the not supported syntax
I fear you have to wait until this is fixed in Rhino.
Hey rbri, i’ve tried it meanwhile with this but it will still faile: