awesomium / awesomium-pub

9 stars 0 forks source link

unable to ExecuteJavascriptWithResult even after main frame is loaded #79

Closed dj-nitehawk closed 8 years ago

dj-nitehawk commented 9 years ago

maybe this is related to issue #75 but could be something else.

i'm on v1.7.5 / vb.net 4.5.1 and using a WebViewType.Offscreen

atm this only happens on 2 web sites that i've come across. namely on: http://www.amazon.com/dp/B00LF10KNA and http://www.washingtonpost.com/

i'm trying to obtain the final rendered html source by executing ExecuteJavascriptWithResult("document.documentElement.outerHTML") from the LoadingFrameCompleted event handler if it's the main frame. it result's in an invalid operation exception and crashes the app if not used inside a try/catch block. it doesn't even return undefined.

i can however `ExecuteJavascriptWithResult from inside the DocumentReady handler but it is only fired once and the returned html source is incomplete at that point in time.

my suspicion is that those pages could be interfering with the DOMContentLoaded events on the page and stops awesomium from detecting the events. so IsDocumentReady is always false.

hope that's enough info for you to reproduce this issue. you can check out this thread-safe wrapper class where i'm experiencing this issue with the above mentioned two sites.

i also tried those 2 sites with the sdk sample projects and the issue is present.

thanks!

dj-nitehawk commented 9 years ago

polling the document ready state of the amazon page with the following handler code:

AddHandler View.DocumentReady, Sub(s, e)
                                   Do Until False
                                       Debug.WriteLine("document.state: " + View.ExecuteJavascriptWithResult("document.readyState"))
                                       Task.Delay(1000).Wait()
                                   Loop
                               End Sub

results in output like so:

document.state: loading
document.state: loading
document.state: loading
document.state: interactive
document.state: interactive
A first chance exception of type 'System.InvalidOperationException' occurred in Awesomium.Core.dll
dj-nitehawk commented 9 years ago

did some more digging around with the following handler code:

    AddHandler View.DocumentReady, Sub(s, e)
                                       RemoveHandler View.DocumentReady, Nothing
                                       View.ExecuteJavascript("var getState = new Function(""return document.readyState;"");")
                                       Dim window As JSObject = View.ExecuteJavascriptWithResult("window")
                                       If Not IsNothing(window) Then
                                           Do While True
                                               Dim res = window.Invoke("getState")
                                               Debug.WriteLine("state: " + res.ToString)
                                               Task.Delay(1000).Wait()
                                           Loop
                                       End If
                                   End Sub

which results in:

state: loading
state: loading
state: interactive
state: interactive
state: interactive
state: interactive
state: interactive
state: interactive

it never goes to 'complete'.

i know this issue is not exactly awesomium's fault but it should know how to handle pages like these.

i've only found 2 so far but i'm sure there's plenty out there :-)

cheers!

Perikles commented 9 years ago

Hello,

This appears to be the same issue as handled in #75. A fix for this is available with the stable release of version 1.7.5 expected within the week.

-- Perikles