Scott's expanded safari webview

Hi, Scott.

Does your plugin allow a youtube video to run within an iframe, or does it expand to full screen like the Corona implementation in the Xcode simulator?

Thanks

Dave

It plays in full screen

Darn, but thanks.

D

Hi, Scott.

I’m working with the safariWebView and have a couple of questions:

1.  The native.newWebVIew, for a local file, takes 2 parameters - the url and a baseDir (in my case system.DocumentsDIrectory)

             Your answer to this is the requestFromFile(path) - which would go as requestFromFile(system.pathFromFile(url,baseDir)): correct?

2.  Shouldnt errors in the loading/display (like file not found) pass through the listener,  setup in the view initialization?

I see status messages in the log, but nothing coming through the listener, and nothing happening on the screen.

Thanks

Dave

Hi, Scott - let’s update the last message.

It looks like I was having some trouble with the javascript in the html file - and it wasnt getting the passed variable.  I got rid of the json call in the listener, since the data coming in was a table - switched to print_r - and was able to figure that part out.

I switched to the requestFromString(x), handled the passed variable myself, and passed the “page” into the request and everything worked as hoped and expected: the youtube video stayed where it was supposed to and played without any of the buffering/timeing issues I see under android.

Did the setup in my last post here look right for the requestFromFile - again, it may have been the javascript that mucked things up.

Thanks

Dave

Good to hear :slight_smile:

Scott,

Should I be able to insert the object into a dispay group?  and should there be a removeSelf() to kill the object?

Thanks

Dave

Unfortunately display groups are not supported, Corona has not provided any documentation on how to implement display groups with native objects.
There is a destroy api

My apologies - totally missed the destroy.

thanks.

Dave

I downloaded the sample “safariWebView-Demo-master” but I’m not able to get it to load a very simple “hello world” index.html local file. I have been trying

view:requestFromFile(system.pathForFile("index.html",system.ResourceDirectory))

But it never displays the local file.

Works fine if I use a web URL like this (and other “https” URLs).

view:request("https://www.coronalabs.com")

What am I doing wrong, any suggestions?

Corona 3184, iPad iOS 11.2

I’m using the requestFromString() under iOS and the standard web view on Android - mainly because of issues with the url variable not being handled properly.  This code runs an embedded youtube video.

local url = "tutorials.html?ID=" .. goto if (ios) then local xx = "\<html\>\<body\>\<div style=\"text-align: center; align: center; background-color: black;\"\>" xx = xx .. "\<iframe style=\'width: 100%; height: 100%;\' src=\"https://www.youtube.com/embed/" .. goto xx = xx .. "?rel=0&amp;controls=0&amp;showinfo=0\" frameborder=\"1\" allowfullscreen\>\</iframe\>\</div\>\</body\>\</html\>" wView:requestFromString(xx) else wView:request(url, system.DocumentsDirectory) end 

I found that Scott’s request() and requestFrom String() ran clean, so I didn’t pursue the requestFromFile().

Not exactly what you were looking for, but hope it helps.

Dave

This has been patched please wait an hour

Scott -

Thank you for providing the patch, loading a local html file is working as expected.

I have another question.  Is it possible to use the “lis(function)” of the safariWebView plugin in the same was as using the corona webView:addEventListener( “urlRequest”, webListener ) to listen while using the html pages?

I used a native.showAlert to see the event.url when the safariWebView plugin loads the index.html page for the first time. Is there something similar I can use to listen for other events like event.url after the page loads?  With the corona webview I use html forms to call functions in corona.  Here is a simple example

function webViewListener( event ) if (event.url == "corona:playVideo1?") then playVideo1() end if (event.url == "corona:openLink1?") then openLink1() end end

Yes it does please see documentation
https://scotth.tech/plugin-safariWebview

Scott -

I see how the listener is working in the Safari WebView Plugin.  It seems to only hear when the initial page is loaded in or when navigating to new pages.  

I have instances where other pages are loaded into a <div> or <iframe> on the page that is loaded in to the Safari WebView Plugin and it does not seem to “hear” when navigating those pages.  When I load a single index.html page that has the listener set to alert the events, I can see the event info when the page initially loads.  But I see nothing when pages load into <div> on the page or when navigating to different pages in those divs.  I only see another listener event if navigating from the index.html to another page at that top level.

The Corona native webview also listens for <form> submit which is actually how I use the listener.  It does not seem that Safari WebView Plugin listener reports any events for a form submit, even on the top level index.html page that I was testing.

Would it be possible to have the Safari WebView Plugin listener hear the events on all the pages that are loaded into plugin even if they are in a <div> or <iframe>?

Is it possible for the Safari WebView Plugin to listen for a <form> submit?

Could you not try to add the data to the url via ?data=mydata

Is there a maximum height or width for the webview?  I am trying to code for iPhone X, Xs, Xr, and Xs Max and no matter what I do I can’t get the webview to get any bigger.  Even if I use obviously too large height and width for the webview.

Have you tried on physical devices?

Scott, is there any way to hide the webview until it has fired the “finished” event?

With Corona’s Native webview, I was showing a loading spinner in Corona rotating, and once the “loaded” event was fired I would set isVisible = true to the webview.

It seems like your webview doesn’t have this functionality. I also tried to load it off screen (x=-1000) and then on “finished” set it to x=display.contentCenterX, but changing the x or y positions seem to do nothing. Also tried having the width as 0 and then setting it once loaded to full width, but again no change occurred.

Please help! Are the position and size properties only allowed to be set on init? Can this be fixed?

Ahhh nvm, it was just a bug/scope issue in my code. For anyone else reading this; changing the x and y properties DOES work.

Awesome job Scott, thanks for your hard work.