[BUG] WebView's url is not updating

[BUG] WebView's url is not updating
0
#1

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.

#2

@slackmoehrle @big_bear :blush:

#3

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.

#4

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")

#5
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);
},
#6

Thanks for updating and posting an example!

1 Like
#7

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.

#8

Understood. But, didnt work for Android as well.

#9

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

#10

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.

#11

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

#12

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

#13

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