gree / unity-webview

zlib License
2.26k stars 687 forks source link

Redirect #459

Open HunteRPVP opened 4 years ago

HunteRPVP commented 4 years ago

Hi! How to enable redirect in your plugin?

KojiNakamaru commented 4 years ago

It works on all platforms, however the osx (Unity Editor) version based on the obsolete WebView has a limitation. That version utilizes the unity:-prefixed URL to send a message back to the Unity side and this is treated as one of redirections and may override a former redirect such as by <meta refresh...>. In the sample app, sample.html modified as below:

diff --git a/sample/Assets/StreamingAssets/sample.html b/sample/Assets/StreamingAssets/sample.html
index 0962587..105bbc2 100644
--- a/sample/Assets/StreamingAssets/sample.html
+++ b/sample/Assets/StreamingAssets/sample.html
@@ -1,6 +1,7 @@
 <html>
   <head>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+    <meta http-equiv="refresh" content="5;url=http://google.com" />
     <title>Unity WebView</title>
     <script src="sample.js"></script>
   </head>

works if you modify SampleWebView.cs as below.

diff --git a/sample/Assets/Scripts/SampleWebView.cs b/sample/Assets/Scripts/SampleWebView.cs
index 1b7596e..561e1cf 100644
--- a/sample/Assets/Scripts/SampleWebView.cs
+++ b/sample/Assets/Scripts/SampleWebView.cs
@@ -92,7 +92,7 @@ public class SampleWebView : MonoBehaviour
                 ");
 #endif
 #endif
-                webViewObject.EvaluateJS(@"Unity.call('ua=' + navigator.userAgent)");
+                //webViewObject.EvaluateJS(@"Unity.call('ua=' + navigator.userAgent)");
             },
             //ua: "custom user agent string",
             enableWKWebView: true);