TLabAltoh / TLabWebViewVR

Sample Unity project for using TLabWebView in OculusQuest. Includes Meta XR SDK and XR Interaction Toolkit implementation example.
https://tlabgames.gitbook.io/tlabwebview/
MIT License
42 stars 9 forks source link

In search of wisdom yet again #9

Closed StefanCiobanu1989 closed 7 months ago

StefanCiobanu1989 commented 1 year ago

hi again, bare with, more coffees are coming. I'm trying to assign an url on runtime to a webview but i have this loop :

TLabWebView[] webviews = duplicate.GetComponentsInChildren<TLabWebView>();
TextMeshPro[] textMeshes = duplicate.GetComponentsInChildren<TextMeshPro>();
foreach (TLabWebView webView in webviews)
{
        webView.SetUserAgent("Mozilla/5.0 (X11; Linux i686; rv:10.0) Gecko/20100101 Firefox/10.0");
        webView.LoadUrl(url);

        foreach (TextMeshPro textMesh in textMeshes)
        {     
            if(textMesh.name == "DebugText"){
                textMesh.text = "UserAgent: "+ webView.GetUserAgent() + "   Url: "+ webView.GetUrl();
            }
        }
}

The Webview is structured as such in my project : image

The "duplicate" object from duplicate.GetComponentsInChildren<TLabWebView>(); represents the assigned EmptyWebView object from the screenshot.

Problem i'm having is:

webView.SetUserAgent("Mozilla/5.0 (X11; Linux i686; rv:10.0) Gecko/20100101 Firefox/10.0");
webView.LoadUrl(url);

dont seem to work as textMesh.text = "UserAgent: "+ webView.GetUserAgent() + " Url: "+ webView.GetUrl(); results in UserAgent and Url being empty. The "url" variable does contain a text string.

If something comes to mind please let me know. The webview is being found, the TextMeshPro object is being found but the set "SetUserAgent" and "LoadUrl" dont seem to get assigned. Thank you!

P.S. I have attempted to add a new function in the TLabWebView.cs called GetUrl() which should return the url on which the page is on, but because of this issue i cant really tell if it's working:

public string GetUrl()
{
    if (!m_webViewEnable)
    {
        return null;
    }

    string currentUrl = null;

#if UNITY_ANDROID
    if (Application.isEditor) return null;

    // Assuming m_NativePlugin is your reference to the native webview component.
    currentUrl = m_NativePlugin.Call<string>("getCurrentUrl");
#endif

    return currentUrl;
}
TLabAltoh commented 1 year ago

Hello.

GetUserAgent() is a function to retrieve the result obtained by CaptureUserAgent(), so please execute it like this.


    public async void SampleUserAgent()

    {
        m_webView.SetUserAgent("Mozilla/5.0 (X11; Linux i686; rv:10.0) Gecko/20100101 Firefox/10.0");
         // The WebView is reloaded at this time.
         // Therefore, it is better to execute LoadUrl() at a different time
        // I will change it so that you can optionally specify whether to reload when setting the user agent

        // Capture the current UserAgent
        // m_webView.CaptureUserAgent()

         // Wait a bit as the plugin runs asynchronously
         await Task.Delay(500);

        Debug.Log("User Agent: " + m_webView.GetUserAgent());

    }

I will also add a function to get the URL later.

This is not a verified code and I may make some changes later...

StefanCiobanu1989 commented 1 year ago

out of curiosity, how many instances can you spawn before it gets laggy ? With just one instance and Web Width = 1280, Web Height 720, Tex Width 1280 Tex Height 720 it starts feeling sluggish , and if i spawn 4 more webviews it feels like it's 10FPS when moving my head around. Sorry to bother, but i need to figure out if i'm doing something wrong..

TLabAltoh commented 1 year ago

Reducing texture resolution may improve performance. When I publish my demos, I have the textures at half the resolution of WevView

TLabAltoh commented 1 year ago

Sorry for the very late update ...

Performance Update

I improved the rendering process of TLabWebView and benchmarked its performance.

I did not record the performance before the improvement, so I cannot compare it, but it should be somewhat better.

Video of benchmarking [web: 1024x1024, tex: 512:512]

GetUrl() Added

GetUrl() has been integrated into the plugin, so please check it out.

Note that for Url and UserAgent, it is necessary to wait to retrieve the results until the page has finished loading.