[Android webview] Will webview.EvaluateJavascript() work if v8 context or Frame is not ready yet?

972 views
Skip to first unread message

santosh mahto

unread,
Aug 12, 2014, 2:45:38 PM8/12/14
to chromi...@chromium.org
Hi All,

As i think V8 context/RenderFrame should be ready in engine to execute javascript using  webview.EvaluateJavascript(android)
Currently in chromium when RenderView, RenderFrame and V8 context is ready it is notified to content layer.(RenderFrameHost)
but not to the application  layer

In android webview  EvaluateJavascript doesn't  bind with v8 context creation or RenderFrame creation.
so Will webview.EvaluateJavascript wait for v8 context /RenderFrame to be created (if not created yet) then execute script or just throw error?

Is it ok to call  EvaluateJavascript just after bare webview object is created in android ?
        webview webview =  new WebView()
        webview-> EvaluateJavascript("var res = 3 +4")

or 

We should first  load webpage with url then call  webview.EvaluateJavascript().

Regards
Santosh

Bo Liu

unread,
Aug 12, 2014, 4:57:14 PM8/12/14
to santosh...@gmail.com, chromium-dev
By android webivew, you mean this java class in the android sdk, right? I was getting confused by the c++ pointer syntax.

If so, then that pattern should work. Webview creates a RenderView inside ContentViewCoreImpl::EvaluateJavaScript if one doesn't exist already: https://code.google.com/p/chromium/codesearch#chromium/src/content/browser/android/content_view_core_impl.cc&l=1341


--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev

santosh mahto

unread,
Aug 12, 2014, 11:18:15 PM8/12/14
to chromi...@chromium.org, santosh...@gmail.com, bo...@chromium.org
Hi  Bo Liu

You are right. its java webview class in android framework.

        webview webview =  new WebView()
        webview EvaluateJavascript("var res = 3 +4").

In ContentViewCore  EvaluateJavascript checks for renderview. But even if RenderView is created  V8 context may not be ready.

I wanted to know On call to EvaluateJavascript,  Does Java layer in android wait internally for  some notification(like OnPageStarted,OnPageFinished) then proceed with 
EvaluateJavascript  call just to ensure that v8 context  is ready by that time.

or  there is no such wait  in android java layer 

Regards
Santosh

Bo Liu

unread,
Aug 13, 2014, 2:01:08 AM8/13/14
to santosh mahto, chromium-dev
On Tue, Aug 12, 2014 at 8:18 PM, santosh mahto <santosh...@gmail.com> wrote:
Hi  Bo Liu

You are right. its java webview class in android framework.

        webview webview =  new WebView()
        webview EvaluateJavascript("var res = 3 +4").

In ContentViewCore  EvaluateJavascript checks for renderview. But even if RenderView is created  V8 context may not be ready.

I wanted to know On call to EvaluateJavascript,  Does Java layer in android wait internally for  some notification(like OnPageStarted,OnPageFinished) then proceed with 
EvaluateJavascript  call just to ensure that v8 context  is ready by that time.

or  there is no such wait  in android java layer 

There is no such wait in the java layer. However we do have a test to verify this use case, so I don't think it's broken: https://code.google.com/p/chromium/codesearch#chromium/src/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java&l=393

Maybe you forgot to enable javascript which is by default off?
Reply all
Reply to author
Forward
0 new messages