native.newWebView's URLRequest event.type 'loaded' not behaving on iOS devices

Hey Joe528:

I tested this fix Tuesday, at the request of Corona engineering staff.  I found a number of issues too… a mostly different set from yours, although I did also find your first observation, namely, that the Mac Simulator operates differently from my iPad device.  I like the way the iPad works better, so that’s good, if not perfect.

On my testing iPad 2, running iOS 7, on build 2090, I did not observe #2… it looked to me that the ‘loaded’ message coincided with the first appearance of the page… but I did see that the page was not always fully loaded.  I find this acceptable, as I am interested in letting the user know that ‘somethings happening’ when I shut down the loading indicator, and the page starting to fill is OK with me towards that end.

#3 looks fatal to me, as my loading indicator will spin forever.  :(  I did not notice this in my testing, although I found something similar with event.type ‘form’ pages… a loading message may or may not be issued for the original form url, and is never issued for any follow-on button presses at the site.  I can live (but don’t like) with never getting a message for the follow on pages, but the flaky first message is a tough one.

When I notified Corona of the results of my testing, I got the impression that ‘it is what it is’.  I wanted to take the Holiday to think about how far down the road this latest fix gets me, and whether I can work with it…

David

Hi cosmic

Thanks for the reply.

Yes, for #1, it’s actually ok.

For #2, the first page is ok, just like what you said, although it’s not fully loaded, at least some part of the page is shown. However, what I really meant, if you click some link after the first page, don’t you get the loaded event before the 2nd page appears on the webView? Except the first page, from my observation, the “only” loaded event comes too early for all subsequent pages.

#3, yes, very fatal, not only your loading indicator will not stop, but also you don’t know the current URL has changed. Besides, this case is a very basic scenario and happens now and then.

I think #3 is definitely a bug, they can’t just consider it is what it is. :unsure: And there are more improvements to this webView and I really hope Corona can put more resources on it.

Hi Joe528,

I am back at it and I need to figure out what to do about these webview issues.  I did not notice the the early loading issue on subsequent pages, but there were definitely more things lurking around in there.

So my question now is this: do I blow off the webview as a feature in my app and push users off to Safari?  (This is very undesirable, as it confuses the novice user as to how to get back… which is clumsy on the iPad in any case.) 

Webview works ‘most of the time’… but is it better that the push off to Safari?  I’m sure my app (using wenview) will take some dings if items #2 and #3 can’t be resolved.  I wish I could figure out a clever work around.

Do you have a simple test app for this?  If so, we should send it to Corona with clear instructions for recreating the issues.  I was using my app as a testing ground, which has a LOT of other distractions.  If you don’t have a simple testing app, I will make one, send it to you, and we can make sure we have a clear set of instructions to reproduce the issues.  I believe the Corona staff will take a good look.

We have looked into the web view issue and believe that we’re correctly passing the message events through that iOS UIWebView provides.

A few items to note:

Web pages/servers can cause multiple loaded events depending on the content, frames, or whether there are redirects, which are passed through from iOS.

It’s important to look for error events in addition to the loaded events since web page loads are not guaranteed (i.e. unreachable hosts, or incomplete loads) We recommend having fallbacks in place to remove activity indicators after a reasonable timeout period has been reached in the event that the page never finishes loading.

The slight variations on OSX and Android are due to differences in implementation at the OS/control level and may differ for specific OS versions.

@cosmic

My app also uses webView heavily. So far, here are the improvements I am really hoping to see before I give up:

(1) Loading events to be more stable for iOS devices (what Bryan01 mentioned about page loads are not guaranteed, it’s understood, but for the problem #3, the new page actually loads but there is no loaded event!)

(2) Share to other apps (this has become quite a standard feature in many other apps when using an embedded webView)

(3) Copy text to the system clipboard (I want to copy the current URL to the clipboard so that the user can paste the URL in other apps, such as WhatsApp)

(4) Current webView is always on top because Corona claims it is the design. I am just wondering if it’s ever possible to make it like other display object so you can do more control with it. For example, when a user clicks some button, show up a panel on top of the webView for more operations. I see most apps with embedded web view has no limitations. Corona should also try it.

I have wrote (2) & (3) to the feature request page (for voting). (4) is probably a dream.

Unless you can connect with them directly, they will just tell you to write a feature request first. For the loading event, it’s possible for them to fix if they are persuaded that the loading event is actually missing instead of page loading problem.

#3 on your list has been released as a beta plugin for ios. See the plugins page for more details

Thanks, Danny!

BTW, is there any way to gain access to the HTML code that comprised the current webview page?

David

Hi Brian,

Thanks for looking into this issue. Glad that you guys are correctly passing message events through the iOS UIWebview. Does this mean that you will soon (or have already) fixed the Corona iOS emulator? Last I looked they’re currently not matching in behaviors in regards to passing message events.

Regards

I have same problem  -_- 
Waiting for solution~ 

After ripping my hair out all day, I’m pretty darn certain I’m experiencing a failure of event.type = “loaded” not propagating on iOS 8 using Corona SDK 2467 (works fine in the simulator.)  So… BUMP!

If you feel this is a bug, please create an example app that shows the problem and file a bug report.  It needs to be complete with a config.lua, build.settings and any assets needed to run it.

Please post the bug report number back here when you get the email with it.

Rob

@Rob:

I’ll try but this is tied to a secure backend system and I’ll have to get authorization to expose any of the security keys required to get the website flow to function in a complete working repro of the issue.

After spending hours today working the issue down to specifics, I have now definitely been able to determine that Corona SDK in simulator operates differently than on device (iPhone 6+ running iOS 8.0.2).  Below I show the requisite code and what I get in the Simulator (Mac OS X 10.9.5 using SDK build 2467).  On device, I only get the first event.type == “loaded” and as a result my application fails.

SETUP

– instantiate the webView
local webView = native.newWebView(0, 0, screenW - 100, screenH - 55);
– listen for subsequent urlRequest events
webView:addEventListener( “urlRequest”, scene.webviewListener );

– load the first URL

webView:request(“domain.com/something”);

LISTENER

function scene.webviewListener( event )
  if event.url then
    print( "You are visiting: " … event.url );
  end
  if event.type then
    print( "The event.type is: " … event.type ); – print the type of request
  end
  if event.errorCode then
    – DEBUG:
    – native.showAlert( “Web Services Error”, event.errorMessage, { “OK” } );
  end
  if (event.url and event.type == “loaded”) then
    – DEBUG:
    native.showAlert( “URL Loaded”, event.url, { “OK” } );  –  THIS ONLY FIRES FOR THE FIRST LOADED EVENT SHOWN BELOW
  end
end

CONSOLE REPORTS IN SIMULATOR (I’ve changed the domain name for my client)

10/18/14 8:47:30.047 PM Corona Simulator[21610]: webviewListener:
10/18/14 8:47:30.047 PM Corona Simulator[21610]: You are visiting: https://domain.com/SPMTM/?empty-cart=1&to-cart=SPMTM_2014_Xmas_WWW_1-5-2&cacheBypass=86665.543
10/18/14 8:47:30.047 PM Corona Simulator[21610]: The event.type is: other
10/18/14 8:47:30.793 PM Corona Simulator[21610]: webviewListener:
10/18/14 8:47:30.793 PM Corona Simulator[21610]: You are visiting: https://domain.com/SPMTM/?empty-cart=1&to-cart=SPMTM_2014_Xmas_WWW_1-5-2&cacheBypass=86665.543
10/18/14 8:47:30.794 PM Corona Simulator[21610]: The event.type is: loaded

10/18/14 8:47:30.794 PM Corona Simulator[21610]: webviewListener:
10/18/14 8:47:30.794 PM Corona Simulator[21610]: You are visiting: https://domain.com/SPMTM/to-cart/?add-to-cart=393&quantity=1&attribute_pa_headwear=ruby_xmaselfhat&attribute_pa_neckwear=ruby_xmassantabeard&attribute_pa_uppertorso=ruby_xmaselfsuit&variation_id=4060&submit=submit
10/18/14 8:47:30.794 PM Corona Simulator[21610]: The event.type is: other
10/18/14 8:47:32.364 PM Corona Simulator[21610]: webviewListener:
10/18/14 8:47:32.364 PM Corona Simulator[21610]: You are visiting: https://domain.com/SPMTM/cart/
10/18/14 8:47:32.364 PM Corona Simulator[21610]: The event.type is: other
10/18/14 8:47:33.302 PM Corona Simulator[21610]: webviewListener:
10/18/14 8:47:33.303 PM Corona Simulator[21610]: You are visiting: https://domain.com/SPMTM/cart/
10/18/14 8:47:33.303 PM Corona Simulator[21610]: The event.type is: loaded

10/18/14 8:47:38.033 PM Corona Simulator[21610]: webviewListener:
10/18/14 8:47:38.033 PM Corona Simulator[21610]: You are visiting: https://domain.com/SPMTM/cart/
10/18/14 8:47:38.033 PM Corona Simulator[21610]: The event.type is: form
10/18/14 8:47:38.808 PM Corona Simulator[21610]: webviewListener:
10/18/14 8:47:38.808 PM Corona Simulator[21610]: You are visiting: https://domain.com/SPMTM/cart/
10/18/14 8:47:38.808 PM Corona Simulator[21610]: The event.type is: loaded

10/18/14 8:47:40.907 PM Corona Simulator[21610]: webviewListener:
10/18/14 8:47:40.907 PM Corona Simulator[21610]: You are visiting: https://domain.com/SPMTM/cart/
10/18/14 8:47:40.907 PM Corona Simulator[21610]: The event.type is: form
10/18/14 8:47:41.478 PM Corona Simulator[21610]: webviewListener:
10/18/14 8:47:41.478 PM Corona Simulator[21610]: You are visiting: https://domain.com/SPMTM/checkout/
10/18/14 8:47:41.478 PM Corona Simulator[21610]: The event.type is: form
10/18/14 8:47:44.731 PM Corona Simulator[21610]: webviewListener:
10/18/14 8:47:44.731 PM Corona Simulator[21610]: You are visiting: https://domain.com/SPMTM/checkout/
10/18/14 8:47:44.731 PM Corona Simulator[21610]: The event.type is: loaded

10/18/14 8:47:48.680 PM Corona Simulator[21610]: webviewListener:
10/18/14 8:47:48.680 PM Corona Simulator[21610]: You are visiting: https://domain.com/SPMTM/checkout/order-received/4767?key=wc_order_544334644b62a
10/18/14 8:47:48.681 PM Corona Simulator[21610]: The event.type is: other
10/18/14 8:47:49.260 PM Corona Simulator[21610]: webviewListener:
10/18/14 8:47:49.260 PM Corona Simulator[21610]: You are visiting: https://domain.com/SPMTM/checkout/order-received/4767/?key=wc_order_544334644b62a
10/18/14 8:47:49.260 PM Corona Simulator[21610]: The event.type is: other
10/18/14 8:47:49.959 PM Corona Simulator[21610]: webviewListener:
10/18/14 8:47:49.959 PM Corona Simulator[21610]: You are visiting: https://domain.com/SPMTM/checkout/order-received/4767/?key=wc_order_544334644b62a
10/18/14 8:47:49.959 PM Corona Simulator[21610]: The event.type is: loaded

 

There’s also another bug. If I enter an invalid URL there’s no event.errorCode or event.errorMessage in the simulator, so you can’t check and close the view. It works on my iphone though. (I’m using Corona SDK 2468)

@beckslash, can you file a bug report on that?  it seems like it should be easy for you to reproduce.  Make sure to include a build.settings and config.lua and any assets needed.

Thanks

Rob

After ripping my hair out all day, I’m pretty darn certain I’m experiencing a failure of event.type = “loaded” not propagating on iOS 8 using Corona SDK 2467 (works fine in the simulator.)  So… BUMP!

If you feel this is a bug, please create an example app that shows the problem and file a bug report.  It needs to be complete with a config.lua, build.settings and any assets needed to run it.

Please post the bug report number back here when you get the email with it.

Rob

@Rob:

I’ll try but this is tied to a secure backend system and I’ll have to get authorization to expose any of the security keys required to get the website flow to function in a complete working repro of the issue.

After spending hours today working the issue down to specifics, I have now definitely been able to determine that Corona SDK in simulator operates differently than on device (iPhone 6+ running iOS 8.0.2).  Below I show the requisite code and what I get in the Simulator (Mac OS X 10.9.5 using SDK build 2467).  On device, I only get the first event.type == “loaded” and as a result my application fails.

SETUP

– instantiate the webView
local webView = native.newWebView(0, 0, screenW - 100, screenH - 55);
– listen for subsequent urlRequest events
webView:addEventListener( “urlRequest”, scene.webviewListener );

– load the first URL

webView:request(“domain.com/something”);

LISTENER

function scene.webviewListener( event )
  if event.url then
    print( "You are visiting: " … event.url );
  end
  if event.type then
    print( "The event.type is: " … event.type ); – print the type of request
  end
  if event.errorCode then
    – DEBUG:
    – native.showAlert( “Web Services Error”, event.errorMessage, { “OK” } );
  end
  if (event.url and event.type == “loaded”) then
    – DEBUG:
    native.showAlert( “URL Loaded”, event.url, { “OK” } );  –  THIS ONLY FIRES FOR THE FIRST LOADED EVENT SHOWN BELOW
  end
end

CONSOLE REPORTS IN SIMULATOR (I’ve changed the domain name for my client)

10/18/14 8:47:30.047 PM Corona Simulator[21610]: webviewListener:
10/18/14 8:47:30.047 PM Corona Simulator[21610]: You are visiting: https://domain.com/SPMTM/?empty-cart=1&to-cart=SPMTM_2014_Xmas_WWW_1-5-2&cacheBypass=86665.543
10/18/14 8:47:30.047 PM Corona Simulator[21610]: The event.type is: other
10/18/14 8:47:30.793 PM Corona Simulator[21610]: webviewListener:
10/18/14 8:47:30.793 PM Corona Simulator[21610]: You are visiting: https://domain.com/SPMTM/?empty-cart=1&to-cart=SPMTM_2014_Xmas_WWW_1-5-2&cacheBypass=86665.543
10/18/14 8:47:30.794 PM Corona Simulator[21610]: The event.type is: loaded

10/18/14 8:47:30.794 PM Corona Simulator[21610]: webviewListener:
10/18/14 8:47:30.794 PM Corona Simulator[21610]: You are visiting: https://domain.com/SPMTM/to-cart/?add-to-cart=393&quantity=1&attribute_pa_headwear=ruby_xmaselfhat&attribute_pa_neckwear=ruby_xmassantabeard&attribute_pa_uppertorso=ruby_xmaselfsuit&variation_id=4060&submit=submit
10/18/14 8:47:30.794 PM Corona Simulator[21610]: The event.type is: other
10/18/14 8:47:32.364 PM Corona Simulator[21610]: webviewListener:
10/18/14 8:47:32.364 PM Corona Simulator[21610]: You are visiting: https://domain.com/SPMTM/cart/
10/18/14 8:47:32.364 PM Corona Simulator[21610]: The event.type is: other
10/18/14 8:47:33.302 PM Corona Simulator[21610]: webviewListener:
10/18/14 8:47:33.303 PM Corona Simulator[21610]: You are visiting: https://domain.com/SPMTM/cart/
10/18/14 8:47:33.303 PM Corona Simulator[21610]: The event.type is: loaded

10/18/14 8:47:38.033 PM Corona Simulator[21610]: webviewListener:
10/18/14 8:47:38.033 PM Corona Simulator[21610]: You are visiting: https://domain.com/SPMTM/cart/
10/18/14 8:47:38.033 PM Corona Simulator[21610]: The event.type is: form
10/18/14 8:47:38.808 PM Corona Simulator[21610]: webviewListener:
10/18/14 8:47:38.808 PM Corona Simulator[21610]: You are visiting: https://domain.com/SPMTM/cart/
10/18/14 8:47:38.808 PM Corona Simulator[21610]: The event.type is: loaded

10/18/14 8:47:40.907 PM Corona Simulator[21610]: webviewListener:
10/18/14 8:47:40.907 PM Corona Simulator[21610]: You are visiting: https://domain.com/SPMTM/cart/
10/18/14 8:47:40.907 PM Corona Simulator[21610]: The event.type is: form
10/18/14 8:47:41.478 PM Corona Simulator[21610]: webviewListener:
10/18/14 8:47:41.478 PM Corona Simulator[21610]: You are visiting: https://domain.com/SPMTM/checkout/
10/18/14 8:47:41.478 PM Corona Simulator[21610]: The event.type is: form
10/18/14 8:47:44.731 PM Corona Simulator[21610]: webviewListener:
10/18/14 8:47:44.731 PM Corona Simulator[21610]: You are visiting: https://domain.com/SPMTM/checkout/
10/18/14 8:47:44.731 PM Corona Simulator[21610]: The event.type is: loaded

10/18/14 8:47:48.680 PM Corona Simulator[21610]: webviewListener:
10/18/14 8:47:48.680 PM Corona Simulator[21610]: You are visiting: https://domain.com/SPMTM/checkout/order-received/4767?key=wc_order_544334644b62a
10/18/14 8:47:48.681 PM Corona Simulator[21610]: The event.type is: other
10/18/14 8:47:49.260 PM Corona Simulator[21610]: webviewListener:
10/18/14 8:47:49.260 PM Corona Simulator[21610]: You are visiting: https://domain.com/SPMTM/checkout/order-received/4767/?key=wc_order_544334644b62a
10/18/14 8:47:49.260 PM Corona Simulator[21610]: The event.type is: other
10/18/14 8:47:49.959 PM Corona Simulator[21610]: webviewListener:
10/18/14 8:47:49.959 PM Corona Simulator[21610]: You are visiting: https://domain.com/SPMTM/checkout/order-received/4767/?key=wc_order_544334644b62a
10/18/14 8:47:49.959 PM Corona Simulator[21610]: The event.type is: loaded

 

There’s also another bug. If I enter an invalid URL there’s no event.errorCode or event.errorMessage in the simulator, so you can’t check and close the view. It works on my iphone though. (I’m using Corona SDK 2468)

@beckslash, can you file a bug report on that?  it seems like it should be easy for you to reproduce.  Make sure to include a build.settings and config.lua and any assets needed.

Thanks

Rob

Seems to be still happening, the loaded event type never occurs on iOS (8.3)

Any workaround tips until this is fixed please?

Cheers