{"id":13664863,"url":"https://github.com/gree/unity-webview","last_synced_at":"2025-05-14T00:10:35.723Z","repository":{"id":3049120,"uuid":"4070520","full_name":"gree/unity-webview","owner":"gree","description":null,"archived":false,"fork":false,"pushed_at":"2025-04-30T00:39:19.000Z","size":109462,"stargazers_count":2422,"open_issues_count":436,"forks_count":704,"subscribers_count":120,"default_branch":"master","last_synced_at":"2025-04-30T01:29:57.093Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Objective-C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"zlib","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gree.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2012-04-19T01:42:10.000Z","updated_at":"2025-04-30T00:39:23.000Z","dependencies_parsed_at":"2023-07-05T19:48:35.658Z","dependency_job_id":"85707e5d-9967-4b13-92ed-64c440d4110e","html_url":"https://github.com/gree/unity-webview","commit_stats":{"total_commits":694,"total_committers":42,"mean_commits":"16.523809523809526","dds":"0.13400576368876083","last_synced_commit":"5daaa90e847dffd70155bd636a26f205807d30fc"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gree%2Funity-webview","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gree%2Funity-webview/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gree%2Funity-webview/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gree%2Funity-webview/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gree","download_url":"https://codeload.github.com/gree/unity-webview/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254044334,"owners_count":22005136,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T05:03:10.231Z","updated_at":"2025-05-14T00:10:30.713Z","avatar_url":"https://github.com/gree.png","language":"Objective-C++","readme":"# unity-webview\n\n`unity-webview` is a Unity 5 (and newer) plugin that overlays WebView components on Unity's rendering view. It supports Android, iOS, Unity Web Player, and Mac (Windows is not supported at this time).\n\nThis plugin is derived from [keijiro-san's Unity WebView Integration](https://github.com/keijiro/unity-webview-integration).\n\n**Note:** This plugin overlays native WebView/WKWebView views over Unity's rendering view and does not support these views in 3D. For alternative solutions, refer to [this issue comment](https://github.com/gree/unity-webview/issues/612#issuecomment-724541385).\n\n## Getting Started\n\nWe recommend starting from the sample project (under the `sample/` directory of the repo) as everything is already preconfigured :\n1. Clone this repo\n2. Open `sample/Assets/Sample.unity` to open the sample project in Unity (If you have a newer unity you will be warned that issues may occur but in general it is fine so click continue. You can also be warned that the project has issues but continue anyways because we will import the necessary packages).\n2. Double click on `dist/unity-webview.unitypackage` to open it in Unity and click on `import` to import the package to your Unity project (You can also use the package manager if you prefer). If you've imported `unity-webview` before, it might be easier to extract `dist/unity-webview.zip`.\n3. Click on the `SampleWebView` gameobject and put the url that you want to open by default (if http, refer to the cleartraffictext section).\n4. Select the platform you want to export to\n5. Build\n\nIf you want to make the webview fullscreen :\n1. Open `Assets/Scripts/SampleWebView.cs`\n2. Edit this line ```webViewObject.SetMargins(0, 0, 0, 0);```\n\nIf you want to make the webview transparent (the background is the Unity scene) :\n1. Open `Assets/Scripts/SampleWebView.cs`\n2. Uncomment(or add in the webViewObject.Init function if it doesn't exist) this line ```transparent: true```\n3. Add and remove a comma accordingly to the code\n\n**Note:** For Android, the current implementation uses Android Fragment to enable the file input field. This might cause new issues. If you don't need the file input field, you can use `dist/unity-webview-nofragment.unitypackage` or `dist/unity-webview-nofragment.zip`.\n**Issues** If you have a blank white page, please make sure to see the clearTraffictext section of this README \n\n## Package Manager\n\nFor Unity 2019.4 or later, import the plugin using the Package Manager by adding the following entry to your `Packages/manifest.json`:\n\n```json\n{\n  \"dependencies\": {\n    \"net.gree.unity-webview\": \"https://github.com/gree/unity-webview.git?path=/dist/package\"\n  }\n}\n```\n\nFor the variant without Fragment:\n\n```json\n{\n  \"dependencies\": {\n    \"net.gree.unity-webview\": \"https://github.com/gree/unity-webview.git?path=/dist/package-nofragment\"\n  }\n}\n```\n\n**Note:** Importing with the Package Manager does not work well for WebGL. Refer to the instructions for `dist/unity-webview.unitypackage`.\n\n## General Notes\nIf you start from the `sample` project, most of the time you just have to comment and uncomment to make the webview fit your needs.\n\nPlease also  note that the Init function of the `Assets/Plugins/Editor/UnityWebViewPostprocessBuild.cs` has a lot of parameters and can be quite long.\n\nIf you have a blank screen, it is most likely that you used HTTP (instead of HTTPS) or self signed certificates. In this case, please refer to the `use Cleartext Traffic` section of this README.\n\nYou can call JS functions via Unity with the webViewObject.EvaluateJS() function even if your JS is served by a server. However, you cannot launch Unity functions from JS.\nTo do this, you will either have to use [this repo](https://github.com/zouloux/unity-web-view) or to create a JS-\u003eServer-\u003eUnity.\nIf you create a fork that allows a remote Unity to JS communication, feel free to fork this repo, add the functionality and submit your changes via a clear and well described Pull Request\n\n**Warning** : Carefully look at the ```#if``` and ```#endif``` because they make parts of the code run or not run depending on the platform and the Editor version. \nYou sometimes have to look at them to be sure that the code you add or edit will be executed.\n\n## Platform-Specific Notes\n\n### Mac (Editor)\n\n#### macOS Version\n\nThe implementation uses [WKWebView’s `takeSnapshotWithConfiguration`](https://developer.apple.com/documentation/webkit/wkwebview/2873260-takesnapshotwithconfiguration) to capture an offscreen WebView image. macOS 10.13 (High Sierra) or later is required.\n\n#### App Transport Security\n\nSince Unity 5.3.0, Unity.app is built with ATS (App Transport Security) enabled, which does not permit non-secured (HTTP) connections. To open HTTP URLs in the Unity Mac Editor, update `/Applications/Unity5.3.4p3/Unity.app/Contents/Info.plist` as follows:\n\n```diff\n--- Info.plist~  2016-04-11 18:29:25.000000000 +0900\n+++ Info.plist   2016-04-15 16:17:28.000000000 +0900\n@@ -57,5 +57,10 @@\n  \u003cstring\u003eEditorApplicationPrincipalClass\u003c/string\u003e\n  \u003ckey\u003eUnityBuildNumber\u003c/key\u003e\n  \u003cstring\u003eb902ad490cea\u003c/string\u003e\n+ \u003ckey\u003eNSAppTransportSecurity\u003c/key\u003e\n+ \u003cdict\u003e\n+   \u003ckey\u003eNSAllowsArbitraryLoads\u003c/key\u003e\n+   \u003ctrue/\u003e\n+ \u003c/dict\u003e\n \u003c/dict\u003e\n \u003c/plist\u003e\n```\n\nAlternatively, execute the following terminal command:\n\n```bash\n/usr/libexec/PlistBuddy -c \"Add NSAppTransportSecurity:NSAllowsArbitraryLoads bool true\" /Applications/Unity/Unity.app/Contents/Info.plist\n```\n\n##### References\n\n* https://github.com/gree/unity-webview/issues/64\n* https://onevcat.zendesk.com/hc/en-us/articles/215527307-I-cannot-open-the-web-page-in-Unity-Editor-\n\n#### Separate Mode\n\nSpecify `separated: true` to open WebView in a separate window:\n\n```csharp\nwebViewObject = (new GameObject(\"WebViewObject\")).AddComponent\u003cWebViewObject\u003e();\nwebViewObject.Init(\n#if UNITY_EDITOR\n    separated: true\n#endif\n    ...);\n```\n\nThis allows the use of the Safari debugger, based on [pull request #161](https://github.com/gree/unity-webview/pull/161).\n\n### iOS\n\n#### Enable WKWebView\n\nWKWebView is supported but disabled by default. Enable it with:\n\n```csharp\nwebViewObject = (new GameObject(\"WebViewObject\")).AddComponent\u003cWebViewObject\u003e();\nwebViewObject.Init(\n    ...\n    enableWKWebView: true);\n```\n[cf.](https://github.com/gree/unity-webview/blob/de9a25c0ab0622b15c15ecbc0c7cd85858aa7745/sample/Assets/Scripts/SampleWebView.cs#L94)\n\nThis flag has no effect on platforms without WKWebView (e.g., iOS7 and Android) and should be set to `true` for iOS9 or later.\n\n#### WKWebView Only Implementation for iOS9 or later\n\nApple now warns against using `UIWebView` APIs :\n\n\u003e ITMS-90809: Deprecated API Usage - Apple will stop accepting submissions of apps that use\n\u003e UIWebView APIs . See https://developer.apple.com/documentation/uikit/uiwebview for more\n\u003e information.\n\nThe plugin includes two variations: `Assets/Plugins/iOS/WebView.mm` and `Assets/Plugins/iOS/WebViewWithUIWebView.mm`. Use `WebView.mm` for iOS9 or later. \nModify `#if __IPHONE_OS_VERSION_MIN_REQUIRED \u003c __IPHONE_9_0` in these files if needed.\n\n*NOTE: WKWebView is available since iOS8 but was largely changed in iOS9, so we use `___IPHONE_9_0` instead of `__IPHONE_8_0`*\n*NOTE: Several versions of Unity themselves also have the ITMS-90809 issue (cf. https://issuetracker.unity3d.com/issues/ios-apple-throws-deprecated-api-usage-warning-for-using-uiwebview-when-submitting-builds-to-the-app-store-connect ).*/\n\n#### XMLHttpRequest for File URLs\n\nWKWebView doesn't allow to access file URLs with XMLHttpRequest. This limitation can be relaxed by `allowFileAccessFromFileURLs`/`allowUniversalAccessFromFileURLs` settings. Those are however private APIs so currently disabled by default. For enabling them, please define `UNITYWEBVIEW_IOS_ALLOW_FILE_URLS`.\n\ncf. https://github.com/gree/unity-webview/issues/785\ncf. https://github.com/gree/unity-webview/issues/224#issuecomment-640642516\n\n### Android\n\nSince `Assets/Plugins/src` is deprecated in recent Unity versions, we switched to .aar files (Android Archive Library).\nIf you need to edit some AndroidManifest.xml files :\n1. Opening the `plugin`folder of this repo in Android Studio\n2. Make somes changes (most of the time edit the `plugin/Android/webview/src/main/AndroidManifest.xml`).\n3. Build the app\n4. You will see your aar file in `build/outputs/aar/`\n5. Move this file to `Assets/Plugins/Android/`\n\n#### File Input Field\n\nThe Android implementation uses Android Fragment for file input fields since [here](https://github.com/gree/unity-webview/commit/a1a2a89d2d0ced366faed9db308ccf4f689a7278)  and may cause new issues that were not found before. \nIf you don't need the file input field, you can install `dist/unity-webview-nofragment.unitypackage` or `dist/unity-webview-nofragment.zip` for selecting the variant without Fragment.\n\nTo enable file input fields, set the following permissions:\n\n* `android.permission.READ_EXTERNAL_STORAGE`\n* `android.permission.WRITE_EXTERNAL_STORAGE`\n* `android.permission.CAMERA`\n\nSet `android.permission.WRITE_EXTERNAL_STORAGE` in `Player Settings/Other Settings/Write Permission` and `android.permission.CAMERA` by defining `UNITYWEBVIEW_ANDROID_ENABLE_CAMERA`. (cf. [Camera/Audio Permission/Feature](#cameraaudio-permissionfeature)).\n\n#### Hardware Acceleration\n\nEnsure the main activity has `android:hardwareAccelerated=\"true\"`:\n\n- **Unity 2018.1 or newer:** Use [UnityWebViewPostprocessBuild.cs](https://forum.unity.com/threads/android-hardwareaccelerated-is-forced-false-in-all-activities.532786/) to set this automatically. (Note that it is already set up in the `sample` project)\n- **Unity 2017.x - 2018.0:** Manually edit `AndroidManifest.xml` as Unity forces `android:hardwareAccelerated=\"false\"`.\n- **Unity 5.x or older:** Modify `AndroidManifest.xml` after the initial build. *Note: [Unity 5.6.1p4 or newer (including 2017 1.0) seems to fix this issue](https://github.com/gree/unity-webview/pull/212#issuecomment-314952793)*.\n\n#### Uses Cleartext Traffic\n\nTo allow cleartext traffic for API level 28 or higher, define `UNITYWEBVIEW_ANDROID_USES_CLEARTEXT_TRAFFIC` so `UnityWebViewPostprocessBuild.cs` adds `android:usesCleartextTraffic=\"true\"`.\n\n#### Camera/Audio Permissions\n\nTo enable camera and microphone access:\n\nFor allowing camera access (`navigator.mediaDevices.getUserMedia({ video:true })`), please define `UNITYWEBVIEW_ANDROID_ENABLE_CAMERA` so that `Assets/Plugins/Editor/UnityWebViewPostprocessBuild.cs` adds the followings to `AndroidManifest.xml`,\n\n```xml\n  \u003cuses-permission android:name=\"android.permission.CAMERA\" /\u003e\n  \u003cuses-feature android:name=\"android.hardware.camera\" /\u003e\n  \u003cqueries\u003e\n    \u003cintent\u003e\n      \u003caction android:name=\"android.media.action.IMAGE_CAPTURE\" /\u003e\n    \u003c/intent\u003e\n  \u003c/queries\u003e\n```\n\nand call the following on runtime.\n\n```c#\n        webViewObject.SetCameraAccess(true);\n```\n\nFor allowing microphone access (`navigator.mediaDevices.getUserMedia({ audio:true })`), please define `UNITYWEBVIEW_ANDROID_ENABLE_MICROPHONE` so that `Assets/Plugins/Editor/UnityWebViewPostprocessBuild.cs` adds the followings to `AndroidManifest.xml`,\n\n```xml\n  \u003cuses-permission android:name=\"android.permission.MICROPHONE\" /\u003e\n  \u003cuses-feature android:name=\"android.hardware.microphone\" /\u003e\n  \u003cuses-permission android:name=\"android.permission.MODIFY_AUDIO_SETTINGS\" /\u003e\n  \u003cuses-permission android:name=\"android.permission.RECORD_AUDIO\" /\u003e\n```\n\nand call the following on runtime.\n\n```c#\n        webViewObject.SetMicrophoneAccess(true);\n```\n\nDetails for each Unity version are the same as for hardwareAccelerated. Please also note that it is necessary to request permissions at runtime for Android API 23 or later as below:\n\n```diff\ndiff --git a/sample/Assets/Scripts/SampleWebView.cs b/sample/Assets/Scripts/SampleWebView.cs\nindex a62c1ca..a5efe9f 100644\n--- a/sample/Assets/Scripts/SampleWebView.cs\n+++ b/sample/Assets/Scripts/SampleWebView.cs\n@@ -24,6 +24,9 @@ using UnityEngine;\n using UnityEngine.UI;\n using UnityEngine.Networking;\n #endif\n+#if !UNITY_EDITOR \u0026\u0026 UNITY_ANDROID\n+using UnityEngine.Android;\n+#endif\n \n public class SampleWebView : MonoBehaviour\n {\n@@ -31,8 +34,29 @@ public class SampleWebView : MonoBehaviour\n     public GUIText status;\n     WebViewObject webViewObject;\n \n+#if !UNITY_EDITOR \u0026\u0026 UNITY_ANDROID\n+    bool inRequestingCameraPermission;\n+\n+    void OnApplicationFocus(bool hasFocus)\n+    {\n+        if (inRequestingCameraPermission \u0026\u0026 hasFocus) {\n+            inRequestingCameraPermission = false;\n+        }\n+    }\n+#endif\n+\n     IEnumerator Start()\n     {\n+#if !UNITY_EDITOR \u0026\u0026 UNITY_ANDROID\n+        if (!Permission.HasUserAuthorizedPermission(Permission.Camera))\n+        {\n+            inRequestingCameraPermission = true;\n+            Permission.RequestUserPermission(Permission.Camera);\n+        }        \n+        while (inRequestingCameraPermission) {\n+            yield return new WaitForSeconds(0.5f);\n+        }\n+#endif\n         webViewObject = (new GameObject(\"WebViewObject\")).AddComponent\u003cWebViewObject\u003e();\n         webViewObject.Init(\n             cb: (msg) =\u003e\n```\n\n(cf. https://github.com/gree/unity-webview/issues/473#issuecomment-559412496)\n(cf. https://docs.unity3d.com/Manual/android-RequestingPermissions.html)\n\n#### `navigator.onLine`\n\nEnable `navigator.onLine` by defining `UNITYWEBVIEW_ANDROID_ENABLE_NAVIGATOR_ONLINE`. The plugin will check `Application.internetReachability` and update WebView's `setNetworkAvailable()`.\n\n#### Margin Adjustment for Keyboard Popup\nThis plugin adjusts the bottom margin temporarily when the keyboard pops up to keep the focused input field displayed. This adjustment is however disabled for some cases (non-fullscreen mode or both portrait/landscape are enabled) to avoid odd behaviours (cf. https://github.com/gree/unity-webview/pull/809 ). Please define `UNITYWEBVIEW_ANDROID_FORCE_MARGIN_ADJUSTMENT_FOR_KEYBOARD` to force the margin adjustment even for these cases.\n\n#### How to build WebViewPlugin-*.aar.tmpl\n\nUnityWebViewPostprocessBuild.cs will select one of WebViewPlugin-*.aar.tmpl depending on EditorUserSettings.development. You can build these files as below:\n\n1. Install Unity 2019.4.40f1 with Android Build Support by Unity Hub.\n   * Also install Unity 5.6.1f1 from https://unity.com/ja/releases/editor/whats-new/5.6.1 and specify `--zorderpatch` if you need to include CUnityPlayer and CUnityPlayerActivity (cf. [Unity 5.x or older](#unity-5x-or-older)).\n2. Open Terminal (mac) or Git Bash (windows), `cd plugins/Android`, and invoke `./install.sh`.\n\nIf successful, you should find `build/Packager/Assets/Plugins/Android/WebViewPlugin-*.aar.tmpl`. install.sh has the following options:\n\n```\nUsage: ./install.sh [OPTIONS]\n\nOptions:\n\n  --nofragment\t\tbuild a nofragment variant.\n  --development\t\tbuild a development variant.\n  --zorderpatch\t\tbuild with the patch for 5.6.0 and 5.6.1 (except 5.6.1p4)\n\n```\n\n### WebGL\n\n*NOTE: for Unity 2020.1.0f1 or newer, please use `unity-webview-2020` instead of `unity-webview` below.*\n\nAfter importing `dist/unity-webview.unitypackage` or `dist/unity-webview.zip`, please copy \n`WebGLTemplates/Default/TemplateData` from your Unity installation to `Assets/WebGLTemplates/unity-webview`. If you utilize Unity 2018.4.13f1 for example,\n\n```bash\n$ cp -a /Applications/Unity/Hub/Editor/2018.4.13f1/PlaybackEngines/WebGLSupport/BuildTools/WebGLTemplates/Default/TemplateData Assets/WebGLTemplates/unity-webview\n```\n\nThen in `Project Settings/Player/Resolution and Presentation`, please select `unity-webview` in `WebGL Template`.\n\n\n## Star History\n\n![Star History Chart](https://api.star-history.com/svg?repos=gree/unity-webview\u0026type=Date)]\n","funding_links":[],"categories":["Open Source Repositories","Objective-C++","iOS / Android","游戏","Open Source Packages"],"sub_categories":["Web View","资源传输下载","Plugins"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgree%2Funity-webview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgree%2Funity-webview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgree%2Funity-webview/lists"}