Using native.newWebView as an in-app WebBrowser

Hi guys,

I am planning to use the ‘native.newWebView’ or ‘native.showWebPopup’ as a browser inside my app (just as a side feature. I know a proper browser will be better).

  1. Are there any limitations to using newWebView/showWebPopup when browsing the web ?

  2. Will history/data/cookies be stored ?

Thanks

I would be interested in an answer to this question, too. Specifically, I have a need to access video online within my game - but the video stream requires javascript to access it.

Webview’s are pretty limited. They do store cookies, however on Android, the cookies do no survive an app restart (it’s they way Android works). I’m not sure how well HTML5 persistant data is saved.  You can have Corona do things on certain taps. It should support HTML5, CSS and Javascript.

I built a weather app and for the Radar, I generated some HTML to load in a map from google, overlay weather underground animated gifs of radar image and used Javascript to make AJAX calls when the map was resized.  You can do a lot with WebViews, but data passing between the webview and Corona space is limited.

Rob

Hi Rob,

Any idea why my native.newWebView on my iPhone 6 Plus is displaying nothing but a window area of WHITE?

The same code works fine in simulator, on my Android and iPad2!!!

I’ve tried variations of my URL and finally figured that if http://www.google.com would not come up, something else is wrong.

The window area displays properly - the problem is that nothing comes up on my iPhone; but is fine on Android and iPad2.

Here is the code:

NOTE: The “V.” prefix represents global variables.

bringUpBrowser("http://www.google.com")

function bringUpBrowser(url)            
    local function webListener( event )
        local shouldLoad = true
        local url = event.url
        if 1 == string.find( url, “corona:close” ) then
            – Close the web popup
            shouldLoad = false
        end
        if event.errorCode then
            – Error loading page
            print( "Error: " … tostring( event.errorMessage ) )
            shouldLoad = false
        end
        return shouldLoad
    end

– V.fieldFactor is 1 for Android and iPads or the coefficient calculation for iPhones (described on another post)

– V.W = screen width, V.H = screen height
    V.webView = native.newWebView(0,0,V.W*V.fieldFactor,V.H*.9*V.fieldFactor)  --90% of the vertical height only, so the App can have a CLOSE button
    V.webView:request(url)
    V.webView:addEventListener(“urlRequest”,webListener)

end

<troylyndon>: It’s possible to use a webview as an in-app web browser. Here’s an example of a Corona SDK-built app that does so: https://itunes.apple.com/app/id1009026110

Unfortunately this is a suboptimal experience: Corona SDK-built apps can’t overlay translucent buttons on top of the webview, can’t hide the controls when scrolling happens, etc. And after four months, with apologies to Rob, Corona has yet to commit to implementing Safari View Controller, which I suspect would take an engineer an afternoon: https://forums.coronalabs.com/topic/58126-corona-sdk-support-for-safari-view-controller-in-ios9/

In terms of your code, for debugging purposes why don’t you replace your global variables with display.contentWidth and display.contentHeight? And, again for debugging purposes, hardcode the URL? It’s really difficult to see what’s going wrong.

The code above is only slightly modified from the Corona API such that the webview window occupies 90% of the vertical screen space, and where a CLOSE button appears in the lower 10%.

I agree with the HUGE need we have for the Safari View Controller - I posted to that string earlier, too.

The white screen appeared to be related to the iOS9 AWS issue (https://forums.coronalabs.com/topic/59319-get-method-network-requests-http-and-https-no-longer-work-in-corona-for-ios-9/) from another post, which is now working.

<troyllyndon>: Glad to hear it’s working! I will take a look at the Safari View Controller thread. I really am mystified why a Corona SDK change that would take an engineer an afternoon has not happened.

I would be interested in an answer to this question, too. Specifically, I have a need to access video online within my game - but the video stream requires javascript to access it.

Webview’s are pretty limited. They do store cookies, however on Android, the cookies do no survive an app restart (it’s they way Android works). I’m not sure how well HTML5 persistant data is saved.  You can have Corona do things on certain taps. It should support HTML5, CSS and Javascript.

I built a weather app and for the Radar, I generated some HTML to load in a map from google, overlay weather underground animated gifs of radar image and used Javascript to make AJAX calls when the map was resized.  You can do a lot with WebViews, but data passing between the webview and Corona space is limited.

Rob

Hi Rob,

Any idea why my native.newWebView on my iPhone 6 Plus is displaying nothing but a window area of WHITE?

The same code works fine in simulator, on my Android and iPad2!!!

I’ve tried variations of my URL and finally figured that if http://www.google.com would not come up, something else is wrong.

The window area displays properly - the problem is that nothing comes up on my iPhone; but is fine on Android and iPad2.

Here is the code:

NOTE: The “V.” prefix represents global variables.

bringUpBrowser("http://www.google.com")

function bringUpBrowser(url)            
    local function webListener( event )
        local shouldLoad = true
        local url = event.url
        if 1 == string.find( url, “corona:close” ) then
            – Close the web popup
            shouldLoad = false
        end
        if event.errorCode then
            – Error loading page
            print( "Error: " … tostring( event.errorMessage ) )
            shouldLoad = false
        end
        return shouldLoad
    end

– V.fieldFactor is 1 for Android and iPads or the coefficient calculation for iPhones (described on another post)

– V.W = screen width, V.H = screen height
    V.webView = native.newWebView(0,0,V.W*V.fieldFactor,V.H*.9*V.fieldFactor)  --90% of the vertical height only, so the App can have a CLOSE button
    V.webView:request(url)
    V.webView:addEventListener(“urlRequest”,webListener)

end

<troylyndon>: It’s possible to use a webview as an in-app web browser. Here’s an example of a Corona SDK-built app that does so: https://itunes.apple.com/app/id1009026110

Unfortunately this is a suboptimal experience: Corona SDK-built apps can’t overlay translucent buttons on top of the webview, can’t hide the controls when scrolling happens, etc. And after four months, with apologies to Rob, Corona has yet to commit to implementing Safari View Controller, which I suspect would take an engineer an afternoon: https://forums.coronalabs.com/topic/58126-corona-sdk-support-for-safari-view-controller-in-ios9/

In terms of your code, for debugging purposes why don’t you replace your global variables with display.contentWidth and display.contentHeight? And, again for debugging purposes, hardcode the URL? It’s really difficult to see what’s going wrong.

The code above is only slightly modified from the Corona API such that the webview window occupies 90% of the vertical screen space, and where a CLOSE button appears in the lower 10%.

I agree with the HUGE need we have for the Safari View Controller - I posted to that string earlier, too.

The white screen appeared to be related to the iOS9 AWS issue (https://forums.coronalabs.com/topic/59319-get-method-network-requests-http-and-https-no-longer-work-in-corona-for-ios-9/) from another post, which is now working.

<troyllyndon>: Glad to hear it’s working! I will take a look at the Safari View Controller thread. I really am mystified why a Corona SDK change that would take an engineer an afternoon has not happened.