[BUG] WebView's url is not updating

Hi CC Team,

I just found out a bug in CC Creator 2.1 (may also be the same in 2.1.1).

Description: When navigating in WebView, the ‘url’ property of it should also be updated with the current url which the WebView is currently displaying. Now, ‘loaded’ event is called whenever navigation happened, but with the wrong url (it always returns only the initial url).

Platform Tested: Web (on Chrome), Android

Edit: Android added.

@slackmoehrle @big_bear :blush:

If you have example code to post to help the team see the issue, please do. We can ask @jare to take a look at this thread to see if your usage is correct and if there is a bug. Thanks for reporting.

Thanks for very fast reply. :slight_smile:

It’s pretty straight forward.

  • setup WebView component

  • setup event listener for ‘loaded’

  • set url of it (eg: https://cocos2d-x.org)

  • then, run the project

  • we will see, https://cocos2d-x.org is loaded and ‘loaded’ event is called with the webview object as parameter. (then you check the URL of it and it will says “https://cocos2d-x.org”)

  • now, inside the webview, click on a link. lets say: “Prodcuts”

  • now, we are at “https://cocos2d-x.org/products” page and the webview will show it accordingly.

  • again, “loaded” event is called again as we went to a new page (which is correct.)

  • now, the problem is the callback event’s webview object’s url is not updated to the new url or the url we loaded (https://cocos2d-x.org/products), but it still shows the initial one ('https://cocos2d-x.org")

properties: {       
    webview: {
        type: cc.WebView,
        default: null
    },
},

onLoad() {
    let ctrl = this;
    ctrl.webview.node.on('loaded', ctrl.webviewLoaded, ctrl);
    ctrl.webview.url = "https://cocos2d-x.org";
},

webviewLoaded(webview) {
    let url = webview.url;
    cc.log("webview url:", url);
},

Thanks for updating and posting an example!

1 Like

sorry, WebView dose’t supported this, because the src attribute of the iframe object only reflects the initially defined URL and does not change with the change of the address in the iframe.

Understood. But, didnt work for Android as well.

Sorry, may not be supported at this time, may be added later

Understood. I will find a workaround.

FYI: it was working in Android using Cocos 3.8 and I am still using it.
But, for new projects, I really don’t want to use old engine.
I just hope, we have backward compatibility while moving forward.

FYI: @knox
The following WebView’s functions are broken as well.

  • evaluateJS
  • edit: “these two are working now” setJavascriptInterfaceScheme & setOnJSCallback

Just follow the official guide below and you would find out none of them work now.
https://docs.cocos.com/creator/manual/en/components/webview.html

Now, WebView became just to show a web site.
There is NO way we can communicate with the Game back and forth as it used to.

Rather than focusing on game codes…
We are spending a lot time for finding out why things didn’t work and fixing Engine’s errors
or finding out a walk-around.
and sadly, it drained a lot energy. :frowning:

cc: @slackmoehrle @jare

Can you give me a demo that I can test? I want to know how you use them

I just called evaluateJS once the page is loaded. And nothing happened. But, I saw some errors in android logcat when evaluateJS is called. (Understand that for HTML5, we need to cross-origin handling, now talking about Android).

Eg: evaluateJS(“alert(‘hello from cocos’)”)

Then, nothing happened, then the following errors were logged in logcat.

jswrapper: [ERROR] ([REMOVED]/build/jsb-default/frameworks/cocos2d-x/cocos/scripting/js-bindings/auto/jsb_webview_auto.cpp, 296): wrong number of arguments: 0, was expecting 1: zygote64

jswrapper: [ERROR] Failed to invoke js_webview_WebView_evaluateJS, location: [REMOVED]/build/jsb-default/frameworks/cocos2d-x/cocos/scripting/js-bindings/auto/jsb_webview_auto.cpp:299: zygote64

The latest version of Cocos Creator (2.1.3) seems to allow this if you still need it.

1 Like

Awesome bro :ok_hand:

2.1.4 or 2.1.3?

Sorry, typo… its 2.1.3