gree / unity-webview

zlib License
2.28k stars 691 forks source link

webview not showing when focus after application pause #979

Open Fuquoc opened 1 year ago

Fuquoc commented 1 year ago

The webview image is not displayed but is still loaded and has sound, is there any way to help me, thank you

KojiNakamaru commented 1 year ago

Could yo please reproduce your issue based on the sample app? I can then investigate it.

Fuquoc commented 1 year ago

during page loading if you exit the application or press the power off button then webview will break I spent all day yesterday debugging but only concluded that it cannot set margin The function webView.Call("SetMargins", (int)ml, (int)mt, (int)mr, (int)mb); still runs normally but nothing happens Please help me, thank you

KojiNakamaru commented 1 year ago

The sample app seems to run correctly when I press the power off button while loading https://google.com . My environment is the followings:

As WebViewObject performs the following,

https://github.com/gree/unity-webview/blob/7d3eb1a7cf5549a8f63cd7a8fa0ef67879e279ba/plugins/WebViewObject.cs#L105

there might be any severe timing issue. You might get a clue by adding Debug.Log() for each webView.Call().

toptomsk commented 1 year ago

I have same issue, do you guys have any suggestion for that? When i press power button the webview is broken and cannot do anything.

KojiNakamaru commented 1 year ago

If you can reproduce the issue based on the sample app and provide the differences, I can investigate the issue further.

toptomsk commented 1 year ago

Here is my sample: https://drive.google.com/file/d/11ZFwbQaB03F9_5-r21IWWkMl7vu3eqLL/view?usp=sharing

But it just appear on one of my devices, not all of theme so it's maybe hard for you to reproduce the error.

And here is video that reproduce the error. https://drive.google.com/file/d/1FPIHNMzdic-OTsrZht0DmCdJuv4ZINow/view?usp=sharing

One more detail, my device is Samsung SM A505F.

Hope you can figure out solution. Thanks

KojiNakamaru commented 1 year ago

Thank you for providing the sample and the movie, those were very helpful. I could reproduce the issue on my device (OSCAL Pad8, Android 11) and found it occured with unity versions including the following fix.

https://issuetracker.unity3d.com/issues/android-unity-app-background-gets-black-when-dialog-window-remains-open-after-re-entering-the-app

I introduced a countermeasure in #983 and it seems okay on my device. Could you please try the latest binaries?

toptomsk commented 1 year ago

Thank you so much. It's working perfectly now.

NunoCardosoYD commented 1 year ago

I'm sorry to barge in, I seem to have a similar problem all of the sudden, but more widespread, for me It suffices to loose focus to loose the surface forever.

I'm using the latest commit (a718fcf9552d5a00cff8fc22fe86aa6819fd0a2d) as a package for unity, and deleted the Library dir and all temporaries to force a full reimport and rebuild on Unity launch.

Weird thing is that something about android must have changed because I even went back to previous commits that worked ok and now they all seem to have this problem, which indicates that something must have changed in android that was never a problem and now it is. (I remember I had a recent system update on the phone)

I recorded a little video including a scrcpy and a filtered logcat of the device (Samsung Galaxy S20 FE 5G with all updates) where it suffices to show the running apps, but this occurs also if i send it to background or close the phone, or go to another app, basically just loose focus and boom, surface gone. https://youtu.be/w_UvXo0RoF0

Thanks in advance, and since this is my first intervention here, congrats for this great project.

PS: I have extra code here that has a built in service worker (for offline iOS), if a sample is needed I'll try to do a simpler version with the extra baggage removed

KojiNakamaru commented 1 year ago

@NunoCardosoYD Which version of unity are you using? Can you reproduce the issue with the original sample app: https://github.com/gree/unity-webview/tree/a718fcf9552d5a00cff8fc22fe86aa6819fd0a2d/sample ?

NunoCardosoYD commented 1 year ago

I'm using Unity 2022.3.10f1. I'll try with that reference sample, will update this as soon as possible

Update 1:

Okay, I'll mention the few steps I took to build and test it: The vanilla sample wanted version 5.6.7f1, I updated to the one I'm using, 2022.3.10f1 Gave me 4 usual errors:

Assets\Scripts\SampleWebView.cs(26,19): error CS0234: The type or namespace name 'UI' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?)
Assets\Scripts\SampleCustomHeader.cs(15,5): error CS0246: The type or namespace name 'WebViewObject' could not be found (are you missing a using directive or an assembly reference?)
Assets\Scripts\SampleWebView.cs(31,12): error CS0246: The type or namespace name 'Text' could not be found (are you missing a using directive or an assembly reference?)
Assets\Scripts\SampleWebView.cs(32,5): error CS0246: The type or namespace name 'WebViewObject' could not be found (are you missing a using directive or an assembly reference?)

Added package https://github.com/gree/unity-webview.git?path=/dist/package, fixed 2 errors Added package Unity UI, fixed the other 2 Changed Default Orientation to Portrait, since Auto Rotation was not working somehow

Tested, same result, made a video with a logcat filtered by "Unity" and added the test of pressing the power button to close the screen and then returning

https://youtu.be/uNwY7gl9kUI

Hope this helps, if you want I can dump the logcat for the exact period when I press to switch apps and then return, maybe that can help

Update 2:

Made a video with "Show Layout Bounds" in Developer Options, and it shows that the surface goes away, and even when destroying the object and then recreating, the surface never comes back. https://youtu.be/7c97aGqnT18

Also added a logcat that starts exactly before pressing the button to switch apps and waited 5 seconds before reselecting the app, then ends, hope this also helps https://drive.google.com/file/d/18eFX-FRjEDPu3eyXzOEI2Qn7BxyRKSrl/view?usp=sharing

KojiNakamaru commented 1 year ago

@NunoCardosoYD Thank you for detailed explanations and videos. I could also reproduce the issue and found that the webview was behind the unity's view by adb shell dumpsys activity top. I introduced https://github.com/gree/unity-webview/pull/985 to compensate for this issue. Could you please try the latest binaries?

NunoCardosoYD commented 1 year ago

Thank you very much @KojiNakamaru, I confirm that it now works perfectly👍, glad that my details helped.