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

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

My workaround is to stop developing apps with webViews via CoronaSDK.

You will find too many problems if you use webView a lot (for example, a news reader app). And the biggest headache is that an Android app with Corona webView crashes in certain situation if your user base is large enough. I keep getting negative feedbacks because of this. And the orientation feature for webView is limited and buggy. My next plan is to go native.

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

Any workaround tips until this is fixed please?

Cheers

My workaround is to stop developing apps with webViews via CoronaSDK.

You will find too many problems if you use webView a lot (for example, a news reader app). And the biggest headache is that an Android app with Corona webView crashes in certain situation if your user base is large enough. I keep getting negative feedbacks because of this. And the orientation feature for webView is limited and buggy. My next plan is to go native.