How can I call platform-specific APIs?

3D WebView's IWebView interface is implemented by a different class on each platform:

In addition to implementing IWebView, these classes also include extra platform-specific methods. As demonstrated below, an application can call a platform-specific static method by accessing it directly on the class, and it can call a platform-specific instance method by casting an IWebView instance to the specific class.

Android

The AndroidWebView and AndroidGeckoWebView classes are only accessible when building for an Android device. Here are examples of calling those classes' static methods:

#if UNITY_ANDROID && !UNITY_EDITOR
  AndroidWebView.SetAudioAndVideoCaptureEnabled(true);
#endif
#if UNITY_ANDROID && !UNITY_EDITOR
  AndroidWebView.EnableRemoteDebugging();
#endif

And here are examples of calling their instance methods:

#if UNITY_ANDROID && !UNITY_EDITOR
  (webViewPrefab.WebView as AndroidWebView).SetIgnoreSslErrors(true);
#endif
#if UNITY_ANDROID && !UNITY_EDITOR
  (webViewPrefab.WebView as AndroidGeckoWebView).PointerDown(point);
#endif

iOS

The iOSWebView class is only accessible when building for an iOS device. Here's an example of calling one of its static methods:

#if UNITY_IOS && !UNITY_EDITOR
  iOSWebView.SetNativeKeyboardEnabled(true);
#endif

And here is an example calling one of its instance methods:

#if UNITY_IOS && !UNITY_EDITOR
  (webViewPrefab.WebView as iOSWebView).SetUserAgent("Custom Browser/1.0");
#endif

Windows and macOS

The StandaloneWebView class is available when running in the editor or building for Standalone. So, #define directives generally aren't needed in order to access its methods:

StandaloneWebView.EnableRemoteDebugging(8080);
(webViewPrefab.WebView as StandaloneWebView).MovePointer(point);

However, if you build your app for other platforms (like Android and iOS), your application will need to use #define directives to prevent StandaloneWebView from being referenced on those platforms:

#if UNITY_STANDALONE || UNITY_EDITOR
  StandaloneWebView.SetCommandLineArguments("--ignore-certificate-errors");
#endif
#if UNITY_STANDALONE || UNITY_EDITOR
  (webViewPrefab.WebView as StandaloneWebView).SetZoomLevel(2.0f);
#endif