### Setting WebView Initialization Options (C#)
Source: https://developer.vuplex.com/webview/releases
Provides an example of using `SetOptionsForInitialization()` on `WebViewPrefab` and `CanvasWebViewPrefab` to configure WebView settings before initialization. This method allows for specific option adjustments during the setup phase.
```csharp
/* Example usage:
WebViewPrefab.SetOptionsForInitialization(new WebViewOptions { ... });
CanvasWebViewPrefab.SetOptionsForInitialization(new WebViewOptions { ... });
*/
```
--------------------------------
### Open VisionOSWindow with Options
Source: https://developer.vuplex.com/webview/VisionOSWindow
This example demonstrates opening the VisionOS window with custom size and position options. Note that Size and Position options require visionOS 2.0 and are ignored on visionOS 1.x.
```csharp
#if UNITY_VISIONOS && !UNITY_EDITOR
webView.Window.Open(
new VisionOSWindowOptions {
Size = new Vector2Int(1000, 1000),
Position = new VisionOSWindowPosition(
VisionOSWindowPositionType.Trailing,
VisionOSWindowPosition.UnityBoundedSceneID
)
}
);
#endif
```
--------------------------------
### Create PDF from WebView (C#)
Source: https://developer.vuplex.com/webview/IWithPdfCreation
Demonstrates how to create a PDF from a web page using the IWithPdfCreation interface. It first checks if the web view supports PDF creation and then calls CreatePdf(). The generated PDF file path is returned, allowing for further manipulation like moving the file. This example assumes the use of Unity's Debug.Log and File.Move functionalities.
```csharp
await webViewPrefab.WaitUntilInitialized();
var webViewWithPdfCreation = webViewPrefab.WebView as IWithPdfCreation;
if (webViewWithPdfCreation == null) {
Debug.Log("This 3D WebView plugin doesn't yet support IWithPdfCreation: " + webViewPrefab.WebView.PluginType);
return;
}
var pdfFilePath = await webViewWithPdfCreation.CreatePdf();
// Now that the PDF has been created, do something with it.
// For example, you can move it to a different location.
File.Move(pdfFilePath, someOtherLocation);
```
--------------------------------
### Check VisionOSWindow Is Open State
Source: https://developer.vuplex.com/webview/VisionOSWindow
This example demonstrates how to check if the VisionOS window is currently open using the IsOpen property. It requires the Unity visionOS platform and is not for the editor.
```csharp
#if UNITY_VISIONOS && !UNITY_EDITOR
var webView = await VisionOSWebView.CreateInWindow();
if (webView.Window.IsOpen) {
Debug.Log("Window is open");
}
#endif
```
--------------------------------
### Dispatching Key Events with IWithKeyDownAndUp (C#)
Source: https://developer.vuplex.com/webview/IWithKeyDownAndUp
This example demonstrates how to dispatch a 'Ctrl + Shift + Right Arrow' key event using the IWithKeyDownAndUp interface. It first checks if the WebView implements the interface and then calls KeyDown and KeyUp methods with the appropriate key and modifiers.
```csharp
// Dispatch ctrl + shift + right arrow
await webViewPrefab.WaitUntilInitialized();
var webViewWithKeyDownAndUp = webViewPrefab.WebView as IWithKeyDownAndUp;
if (webViewWithKeyDownAndUp != null) {
webViewWithKeyDownAndUp.KeyDown("ArrowRight", KeyModifier.Control | KeyModifier.Shift);
webViewWithKeyDownAndUp.KeyUp("ArrowRight", KeyModifier.Control | KeyModifier.Shift);
}
```
--------------------------------
### iOS Info.plist Configuration for Custom URI Schemes
Source: https://developer.vuplex.com/webview/IWithDeepLinking
Example of an Info.plist entry required on iOS to allow custom URI schemes for deep linking. The LSApplicationQueriesSchemes key must contain an array of strings, where each string is a custom scheme (e.g., 'vnd.youtube').
```xml
LSApplicationQueriesSchemes
vnd.youtube
```
--------------------------------
### Install Built-in Extension with AndroidGeckoWebView
Source: https://developer.vuplex.com/webview/AndroidGeckoWebView
Installs a built-in extension using GeckoView's WebExtensionController.ensureBuiltIn() method. The extension is not re-installed if it already exists with the same version. This method is available for Android and when not in the Unity Editor.
```csharp
#if UNITY_ANDROID && !UNITY_EDITOR
AndroidGeckoWebView.EnsureBuiltInExtension(
"resource://android/assets/your-extension/",
"example@example.com"
);
#endif
```
--------------------------------
### WebViewPrefab - Initialization and Basic Usage
Source: https://developer.vuplex.com/webview/WebViewPrefab
This section covers the initialization of WebViewPrefab and how to interact with its core properties and methods.
```APIDOC
## WebViewPrefab
### Description
WebViewPrefab is a MonoBehaviour that simplifies the process of displaying and interacting with an `IWebView` in a 3D world space. It manages the creation of an `IWebView`, renders its texture, and handles user input like clicks, drags, and scrolling. Developers can specify an initial URL or HTML content to be loaded.
For use within a Canvas UI, please refer to `CanvasWebViewPrefab`.
### Instantiation
There are two primary ways to create a `WebViewPrefab` instance:
1. **Editor**: Drag the `WebViewPrefab.prefab` file into your scene and set the "Initial URL" property in the inspector.
2. **Programmatically**: Use `WebViewPrefab.Instantiate()` and then interact with the `WebView` property after initialization.
For advanced customization, consider creating an `IWebView` directly using `Web.CreateWebView()`.
### Public Properties
* **ClickingEnabled** (`bool`): Determines if clicking interactions are enabled. Defaults to `true`.
* **Collider** (`Collider`): Gets the prefab's collider component.
* **CursorIconsEnabled** (`bool`): Controls whether the mouse cursor icon updates based on web page interactions (e.g., changing to a pointer hand over links). Defaults to `true`. (Currently supported on 3D WebView for Windows and macOS).
* **DragMode** (`DragMode`): Configures how drag interactions are handled. Ignored in Native 2D Mode. Refer to documentation for platform-specific limitations (iOS, UWP, Android Gecko).
* **DragThreshold** (`float`): Sets the threshold in web pixels for initiating a drag. Defaults to `20`. Used to differentiate between clicks and drags.
* **HoveringEnabled** (`bool`): Enables or disables hover interactions. Defaults to `true`. Ignored in Native 2D Mode. Refer to documentation for platform-specific limitations (iOS, UWP).
* **InitialUrl** (`string`): Specifies a URL to be loaded automatically when the prefab initializes if set in the editor. Use `IWebView.LoadUrl()` for runtime URL changes.
* **KeyboardEnabled** (`bool`): Determines if the webview automatically receives input from the native keyboard and the Keyboard prefab. Defaults to `true`.
* **LogConsoleMessages** (`bool`): If `true`, JavaScript console messages from `IWebView.ConsoleMessageLogged` will be printed to Unity logs. Defaults to `false`.
* **Material** (`Material`): Gets or sets the prefab's material.
* **NativeOnScreenKeyboardEnabled** (`bool`): Controls the enablement of the native on-screen keyboard.
* **PixelDensity** (`float`): Adjusts the density of pixels for rendering the web view.
* **RemoteDebuggingEnabled** (`bool`): Enables or disables remote debugging for the web view.
* **Resolution** (`float`): Sets the resolution of the web view's texture.
* **ScrollingEnabled** (`bool`): Determines if scrolling interactions are enabled. Defaults to `true`.
* **ScrollingSensitivity** (`float`): Adjusts the sensitivity of scrolling interactions.
* **Visible** (`bool`): Controls the visibility of the web view.
* **WebView** (`IWebView?`): Provides access to the underlying `IWebView` instance.
### Public Methods
* **BrowserToScreenPoint** (`Vector2 BrowserToScreenPoint(int xInPixels, int yInPixels)`): Converts browser coordinates to screen coordinates.
* **Destroy** (`void Destroy()`): Destroys the `WebViewPrefab` instance and its associated web view.
* **Instantiate** (`static WebViewPrefab Instantiate(float width, float height, WebViewOptions options)`): Creates a new `WebViewPrefab` instance with specified dimensions and options.
* **Instantiate** (`static WebViewPrefab Instantiate(float width, float height)`): Creates a new `WebViewPrefab` instance with specified dimensions.
* **Instantiate** (`static WebViewPrefab Instantiate(IWebView webView)`): Creates a new `WebViewPrefab` instance using an existing `IWebView`.
* **Resize** (`void Resize(float width, float height)`): Resizes the web view to the specified dimensions.
* **SetOptionsForInitialization** (`void SetOptionsForInitialization(WebViewOptions options)`): Sets web view options before initialization.
* **SetPointerInputDetector** (`void SetPointerInputDetector(IPointerInputDetector pointerInputDetector)`): Sets a custom pointer input detector.
* **SetWebViewForInitialization** (`void SetWebViewForInitialization(IWebView webView)`): Sets an `IWebView` to be used for initialization.
* **WaitUntilInitialized** (`Task WaitUntilInitialized()`): Asynchronously waits until the web view has finished initializing.
* **WorldToNormalized** (`Vector2 WorldToNormalized(Vector3 worldPoint)`): Converts a world point to normalized coordinates.
### Public Events
* **Clicked** (`EventHandler Clicked`): Fired when the web view is clicked.
* **Initialized** (`EventHandler Initialized`): Fired when the web view has been initialized.
* **PointerEntered** (`EventHandler PointerEntered`): Fired when the pointer enters the web view area.
* **PointerExited** (`EventHandler PointerExited`): Fired when the pointer exits the web view area.
* **Scrolled** (`EventHandler Scrolled`): Fired when the web view is scrolled.
```
--------------------------------
### VisionOSWindowPosition Type Property (C#)
Source: https://developer.vuplex.com/webview/VisionOSWindowPosition
Property to get the type of the VisionOSWindowPosition.
```csharp
VisionOSWindowPositionType Type
```
--------------------------------
### Create and Initialize a WebView Instance
Source: https://developer.vuplex.com/webview/Web
Shows how to create a new IWebView instance programmatically and initialize it with specific dimensions. This method is useful when not using prefabs and allows for custom GameObject integration.
```csharp
var webView = Web.CreateWebView();
// Initialize the webview to 600px x 300px.
await webView.Init(600, 300);
webView.LoadUrl("https://vuplex.com");
// Set the Material attached to this GameObject to display the webview.
GetComponent().material = webView.CreateMaterial();
```
--------------------------------
### Material
Source: https://developer.vuplex.com/webview/CanvasWebViewPrefab
Gets or sets the prefab's material. This property is unused when running in Native 2D Mode.
```APIDOC
## GET /websites/developer_vuplex/Material
### Description
Gets or sets the prefab's material.
### Method
GET/SET
### Endpoint
/websites/developer_vuex/Material
### Parameters
#### Query Parameters
- **Material** (Material) - Required - The prefab's material.
### Response
#### Success Response (200)
- **Material** (Material) - The prefab's material.
#### Important note
This property is unused when running in Native 2D Mode.
```
--------------------------------
### WebViewOptions Configuration
Source: https://developer.vuplex.com/webview/WebViewOptions
Configure options for initializing a WebView, such as focus behavior, video playback, and preferred plugins.
```APIDOC
## WebViewOptions
### Description
Options that can be passed to `WebViewPrefab.Instantiate()` or `SetOptionsForInitialization()` to alter the webview that the prefab creates during initialization.
### Public Properties
- **clickWithoutStealingFocus** (bool) - Optional - If set to `true`, makes it so that clicking on the webview doesn't automatically focus it.
- **disableVideo** (bool) - Optional - Sets whether the fallback video implementation for iOS is disabled. This option is ignored on non-iOS platforms or when Native 2D Mode is enabled.
- **preferredPlugins** (WebPluginType[]) - Optional - Specifies which native plugin to use when multiple plugins are installed for a single platform. Currently only applicable to Android (`WebPluginType.Android`, `WebPluginType.AndroidGecko`). Defaults to `WebPluginType.AndroidGecko` if both are installed, but can be overridden to force `WebPluginType.Android`.
```
--------------------------------
### Cookie Management API
Source: https://developer.vuplex.com/webview/ICookieManager
This section details the methods available for managing HTTP cookies, including getting, setting, and deleting them.
```APIDOC
## DELETE /websites/developer_vuplex/cookies
### Description
Deletes cookies matching the specified URL and optionally a cookie name.
### Method
DELETE
### Endpoint
`/websites/developer_vuplex/cookies`
### Parameters
#### Query Parameters
- **url** (string) - Required - The URL for which to delete cookies.
- **cookieName** (string) - Optional - The specific name of the cookie to delete.
### Response
#### Success Response (200)
- **success** (boolean) - Indicates whether the deletion operation succeeded.
#### Response Example
```json
{
"success": true
}
```
## GET /websites/developer_vuplex/cookies
### Description
Retrieves all cookies that match the specified URL and optionally a cookie name.
### Method
GET
### Endpoint
`/websites/developer_vuplex/cookies`
### Parameters
#### Query Parameters
- **url** (string) - Required - The URL for which to retrieve cookies.
- **cookieName** (string) - Optional - The specific name of the cookie to retrieve.
### Response
#### Success Response (200)
- **cookies** (array) - An array of Cookie objects matching the criteria. Each cookie object may have Name, Value, Domain, Path, Secure, and ExpirationDate fields.
#### Response Example
```json
{
"cookies": [
{
"Name": "example_name",
"Value": "example_value",
"Domain": "vuplex.com",
"Path": "/",
"Secure": true,
"ExpirationDate": 1678886400
}
]
}
```
## POST /websites/developer_vuplex/cookies
### Description
Sets a given HTTP cookie.
### Method
POST
### Endpoint
`/websites/developer_vuplex/cookies`
### Parameters
#### Request Body
- **cookie** (object) - Required - The cookie object to set. Must contain at least Name, Value, Domain, and Path.
- **Name** (string) - Required - The name of the cookie.
- **Value** (string) - Required - The value of the cookie.
- **Domain** (string) - Required - The domain for which the cookie is set.
- **Path** (string) - Required - The path for which the cookie is set.
- **Secure** (boolean) - Optional - Whether the cookie should only be sent over HTTPS.
- **ExpirationDate** (integer) - Optional - The expiration date of the cookie as a Unix timestamp.
### Request Example
```json
{
"cookie": {
"Domain": "vuplex.com",
"Path": "/",
"Name": "example_name",
"Value": "example_value",
"Secure": true,
"ExpirationDate": 1678886400
}
}
```
### Response
#### Success Response (200)
- **success** (boolean) - Indicates whether the cookie was set successfully.
#### Response Example
```json
{
"success": true
}
```
```
--------------------------------
### Instantiate Keyboard Instance
Source: https://developer.vuplex.com/webview/Keyboard
Demonstrates how to create an instance of the Keyboard class. It shows how to use the static Instantiate() method with default dimensions and how to parent it to a WebViewPrefab, setting its local position, rotation, and scale.
```csharp
// Add a keyboard under a WebViewPrefab.
var keyboard = Keyboard.Instantiate();
keyboard.transform.SetParent(webViewPrefab.transform, false);
keyboard.transform.localPosition = new Vector3(0, -0.31f, 0);
keyboard.transform.localEulerAngles = Vector3.zero;
```
--------------------------------
### iOSWebView - SetCameraEnabled
Source: https://developer.vuplex.com/webview/iOSWebView
Enables or disables the camera for the web view. Requires additional setup steps as described in the documentation.
```APIDOC
## PUT /websites/developer_vuplex/iOSWebView/SetCameraEnabled
### Description
Enables or disables the camera for the web view. This method should be used in conjunction with other steps outlined in the documentation to ensure camera functionality.
### Method
PUT
### Endpoint
/websites/developer_vuplex/iOSWebView/SetCameraEnabled
### Parameters
#### Query Parameters
- **enabled** (bool) - Required - Set to `true` to enable the camera, `false` to disable.
### Request Example
```csharp
void Awake() {
#if UNITY_IOS && !UNITY_EDITOR
iOSWebView.SetCameraEnabled(true);
#endif
}
```
### Response
#### Success Response (200)
- **void** - Indicates the operation was successful.
#### Response Example
(No response body for void method)
**Note**: Additional steps are required to successfully enable the camera.
```
--------------------------------
### VisionOSWebView.CreateInWindow() Method
Source: https://developer.vuplex.com/webview/VisionOSWebView
Explains how to create a VisionOSWebView in a native window using default system settings.
```APIDOC
## VisionOSWebView.CreateInWindow() Method
### Description
When running in Unity's RealityKit app mode, this method opens a webview in a native visionOS (SwiftUI) window. The user can reposition, resize, and close the window using native controls. The application can also manipulate the window programmatically via the `VisionOSWebView.Window` property. This method opens the window using the system's default size (1280 x 720 px) and position (in front of the user). To customize the window's initial size and position, use `CreateInWindow(VisionOSWindowOptions)` instead.
### Method
`Task CreateInWindow()`
### Parameters
None
### Request Example
```csharp
#if UNITY_VISIONOS && !UNITY_EDITOR
var webView = await VisionOSWebView.CreateInWindow();
webView.LoadUrl("https://example.com");
// Recommended: Dispose of the webview when the user closes the window.
webView.Window.Closed += (sender, eventArgs) => {
webView.Dispose();
};
#endif
```
### Response
#### Success Response (200)
* **VisionOSWebView** (`Task`) - A Task that resolves to the created VisionOSWebView instance.
### Additional notes
* This method is only supported when the application's app mode is set to RealityKit. It throws an `InvalidOperationException` if invoked when the app mode is set to Metal or Windowed.
* When the window is closed, the webview is not automatically destroyed. The webview remains running and the window can be reopened by calling `Window.Open()`. The webview is only destroyed if `IWebView.Dispose()` is called.
* It's recommended to attach an event handler to the `Window.Closed` event that calls `IWebView.Dispose()` when the user closes the window, unless you intend to reopen it.
```
--------------------------------
### Visible
Source: https://developer.vuplex.com/webview/CanvasWebViewPrefab
Gets or sets whether the instance is visible and responds to raycasts. The default is `true`. Setting this to `false` is often preferable to disabling the prefab's GameObject.
```APIDOC
## GET/SET /websites/developer_vuplex/Visible
### Description
Gets or sets whether the instance is visible and responds to raycasts.
### Method
GET/SET
### Endpoint
/websites/developer_vuplex/Visible
### Parameters
#### Query Parameters
- **Visible** (bool) - Required - `true` if the instance is visible and responds to raycasts, `false` otherwise.
### Response
#### Success Response (200)
- **Visible** (bool) - Indicates if the instance is visible and responds to raycasts.
```
--------------------------------
### PointerOptions Class Details
Source: https://developer.vuplex.com/webview/PointerOptions
Provides an overview of the PointerOptions class, its namespace, and a summary of its public properties.
```APIDOC
## Class: PointerOptions
### Namespace
Vuplex.WebView
### Description
Options to alter pointer methods, like PointerUp() and PointerDown().
### Public Properties
- **Button** (MouseButton) - The button for the event. The default is MouseButton.Left.
- **ClickCount** (int) - The number of clicks for the event. For example, for a double click, set this value to `2`. The default value is `1`.
- **PreventStealingFocus** (bool) - Whether to prevent the click event from stealing focus from the currently focused webview. The default value is `false`.
```
--------------------------------
### Get WebView Size
Source: https://developer.vuplex.com/webview/IWebView
Retrieves the current size of the webview in pixels. This property is useful for determining the dimensions of the rendered web content.
```csharp
// Get the current size of the webview.
await webViewPrefab.WaitUntilInitialized();
Debug.Log("Size: " + webViewPrefab.WebView.Size);
```
--------------------------------
### Instantiate
Source: https://developer.vuplex.com/webview/CanvasWebViewPrefab
Creates a new CanvasWebViewPrefab instance. Multiple overloads allow instantiation with options, with an existing IWebView, or with default settings.
```APIDOC
## Instantiate
### Description
Creates a new CanvasWebViewPrefab instance. Overloads are provided to instantiate with specific options, with an existing IWebView, or with default settings.
### Method
`static CanvasWebViewPrefab Instantiate(WebViewOptions options)`
`static CanvasWebViewPrefab Instantiate()`
`static CanvasWebViewPrefab Instantiate(IWebView webView)`
### Parameters
#### Path Parameters
- None
#### Query Parameters
- None
#### Request Body
- None
### Request Example (Instantiate() with default settings)
```csharp
// Create a CanvasWebViewPrefab
var canvasWebViewPrefab = CanvasWebViewPrefab.Instantiate();
// Position the prefab how we want it
var canvas = GameObject.Find("Canvas");
canvasWebViewPrefab.transform.parent = canvas.transform;
var rectTransform = canvasWebViewPrefab.transform as RectTransform;
rectTransform.anchoredPosition3D = Vector3.zero;
rectTransform.offsetMin = Vector2.zero;
rectTransform.offsetMax = Vector2.zero;
canvasWebViewPrefab.transform.localScale = Vector3.one;
// Load a URL once the prefab finishes initializing
await canvasWebViewPrefab.WaitUntilInitialized();
canvasWebViewPrefab.WebView.LoadUrl("https://vuplex.com");
```
### Response
#### Success Response (200)
- **CanvasWebViewPrefab** - The newly created instance.
#### Response Example
```json
{
"instanceId": "some-unique-id"
}
```
```
--------------------------------
### Get Plugin Type
Source: https://developer.vuplex.com/webview/IWebView
Retrieves the type of the webview plugin. This can be useful for debugging or for implementing logic that depends on the specific plugin implementation.
```csharp
// Get the plugin type of the webview.
await webViewPrefab.WaitUntilInitialized();
Debug.Log("Plugin type: " + webViewPrefab.WebView.PluginType);
```
--------------------------------
### VisionOSWindowPosition RelativeWindowID Property (C#)
Source: https://developer.vuplex.com/webview/VisionOSWindowPosition
Property to get or set the ID of the SwiftUI window or scene to which the position is relative. This is required for most VisionOSWindowPositionType values.
```csharp
string RelativeWindowID
```
--------------------------------
### VisionOSWebView Class Overview
Source: https://developer.vuplex.com/webview/VisionOSWebView
Provides an overview of the VisionOSWebView class, its namespace, and additional feature interfaces it supports, along with a summary of its public properties and methods.
```APIDOC
## VisionOSWebView
### Class
`IWebView`
### Namespace
`Vuplex.WebView`
### Additional feature interfaces
* `IWithDeepLinking`
* `IWithDownloads`
* `IWithFallbackVideo`
* `IWithMovablePointer`
* `IWithNativeJavaScriptDialogs`
* `IWithNativeOnScreenKeyboard`
* `IWithPdfCreation`
* `IWithPointerDownAndUp`
* `IWithPopups`
* `IWithSettableUserAgent`
### Description
VisionOSWebView is the IWebView implementation used by 3D WebView for visionOS. It also includes additional APIs for visionOS-specific functionality.
### Summary
#### Public properties
* `Window` (VisionOSWindow): The native VisionOSWindow instance if created via `CreateInWindow()`, otherwise `null`.
#### Public methods
* `CreateInWindow(VisionOSWindowOptions options)`: Creates a VisionOSWebView in a native window with customizable options.
* `CreateInWindow()`: Creates a VisionOSWebView in a native window with default options.
* `GetNativeWebView()`: Returns the native web view's handle.
* `SetCameraEnabled(bool enabled)`: Enables or disables the camera for the web view.
* `SetMicrophoneEnabled(bool enabled)`: Enables or disables the microphone for the web view.
* `SetTargetFrameRate(uint targetFrameRate)`: Sets the target frame rate for the web view.
```
--------------------------------
### Get IFrame Element ID in WebGL
Source: https://developer.vuplex.com/webview/WebGLWebView
Retrieves the unique ID attribute of the webview's IFrame element. This is useful for directly interacting with the iframe in a WebGL context.
```csharp
await canvasWebViewPrefab.WaitUntilInitialized();
#if UNITY_WEBGL && !UNITY_EDITOR
var webGLWebView = canvasWebViewPrefab.WebView as WebGLWebView;
Debug.Log("IFrame ID: " + webGLWebView.IFrameElementID);
#endif
```
--------------------------------
### VisionOSWebView.CreateInWindow(VisionOSWindowOptions options) Method
Source: https://developer.vuplex.com/webview/VisionOSWebView
Explains how to create a VisionOSWebView in a native window with custom size and position options.
```APIDOC
## VisionOSWebView.CreateInWindow(VisionOSWindowOptions options) Method
### Description
Creates a VisionOSWebView in a native visionOS (SwiftUI) window. This method accepts a `VisionOSWindowOptions` parameter for customizing the window's initial size and position. The VisionOSWindowsOptions.Size and Position options require visionOS 2.0. On visionOS 1.x, the Size and Position options are ignored.
### Method
`Task CreateInWindow(VisionOSWindowOptions options)`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
* **options** (`VisionOSWindowOptions`) - Required - Options for customizing the initial size and position of the window.
### Request Example
```csharp
#if UNITY_VISIONOS && !UNITY_EDITOR
var webView = await VisionOSWebView.CreateInWindow(
new VisionOSWindowOptions {
Size = new Vector2Int(1000, 1000),
Position = new VisionOSWindowPosition(
VisionOSWindowPositionType.Trailing,
VisionOSWindowPosition.UnityBoundedSceneID
)
}
);
// The webview has been displayed to the user in a native window,
// and now you can use IWebView APIs like LoadUrl() and LoadHtml().
webView.LoadUrl("https://vuplex.com");
// Add an event handler that destroys the webview when the user closes the window.
webView.Window.Closed += (sender, eventArgs) => {
webView.Dispose();
};
#endif
```
### Response
#### Success Response (200)
* **VisionOSWebView** (`Task`) - A Task that resolves to the created VisionOSWebView instance.
#### Response Example
(See Request Example for usage)
### Important note
The `VisionOSWindowsOptions.Size` and `Position` options require visionOS 2.0. On visionOS 1.x, the `Size` and `Position` options are ignored, and a window always uses the system's default size and position.
```
--------------------------------
### IWithPixelDensity Interface
Source: https://developer.vuplex.com/webview/IWithPixelDensity
Provides methods to get and set the pixel density of a webview. This is useful for optimizing content display on high DPI monitors.
```APIDOC
## Interface: IWithPixelDensity
### Namespace
Vuplex.WebView
### Description
An interface implemented by a webview if it supports changing its pixel density, which is its number of physical pixels per logical pixel. The default pixel density is `1`, but increasing it to `2` can make web content appear sharper or less blurry on high DPI displays.
### Implemented by
* StandaloneWebView
### Public Methods
#### SetPixelDensity
`void SetPixelDensity(float pixelDensity)`
Sets the pixel density. The value must be between `0` and `10`, and the default is `1`.
**Parameters**
* **pixelDensity** (float) - The desired pixel density. Must be between 0 and 10.
### Public Properties
#### PixelDensity
`float PixelDensity { get; }`
Gets the current pixel density.
**Returns**
* (float) - The current pixel density.
### Example
```csharp
await webViewPrefab.WaitUntilInitialized();
var webViewWithPixelDensity = webViewPrefab.WebView as IWithPixelDensity;
if (webViewWithPixelDensity == null) {
Debug.Log("This 3D WebView plugin doesn\'t yet support IWithPixelDensity: " + webViewPrefab.WebView.PluginType);
} else {
webViewWithPixelDensity.SetPixelDensity(2);
}
```
```
--------------------------------
### Instantiate WebViewPrefab with Size
Source: https://developer.vuplex.com/webview/WebViewPrefab
Creates a new WebViewPrefab instance with specified dimensions. The prefab is then positioned and oriented in the scene. The URL is loaded after the prefab is fully initialized.
```csharp
// Create a 0.5 x 0.5 instance
var webViewPrefab = WebViewPrefab.Instantiate(0.5f, 0.5f);
// Position the prefab how we want it
webViewPrefab.transform.parent = transform;
webViewPrefab.transform.localPosition = new Vector3(0, 0f, 0.5f);
webViewPrefab.transform.LookAt(transform);
// Load a URL once the prefab finishes initializing
await webViewPrefab.WaitUntilInitialized();
webViewPrefab.WebView.LoadUrl("https://vuplex.com");
```
--------------------------------
### IWithPdfCreation Interface Documentation
Source: https://developer.vuplex.com/webview/IWithPdfCreation
Details about the IWithPdfCreation interface, its purpose, implementing classes, and the CreatePdf method.
```APIDOC
## Interface: IWithPdfCreation
### Namespace
Vuplex.WebView
### Implemented By
- AndroidWebView
- iOSWebView
- StandaloneWebView
- VisionOSWebView
### Description
An interface implemented by a webview if it supports creating a PDF from a web page. Created PDFs are saved to Application.temporaryCachePath, but you can move them to a different location after they are created. If you wish to format the PDF differently on Windows and macOS, you can achieve that by using StandaloneWebView.CreatePdf() instead.
#### Important notes
* On iOS, PDF creation is only supported on iOS 14 and newer.
* On iOS and visionOS, generated PDFs are not paginated (i.e. the PDF is one long page) due to a limitation of WKWebView's PDF functionality.
### Public Methods
#### Task CreatePdf()
Creates a PDF from the current web page and returns the full file path of the created PDF. PDFs are saved to Application.temporaryCachePath, but you can move them to a different location after they are created.
### Example Usage
```csharp
await webViewPrefab.WaitUntilInitialized();
var webViewWithPdfCreation = webViewPrefab.WebView as IWithPdfCreation;
if (webViewWithPdfCreation == null) {
Debug.Log("This 3D WebView plugin doesn\'t yet support IWithPdfCreation: " + webViewPrefab.WebView.PluginType);
return;
}
var pdfFilePath = await webViewWithPdfCreation.CreatePdf();
// Now that the PDF has been created, do something with it.
// For example, you can move it to a different location.
File.Move(pdfFilePath, someOtherLocation);
```
```
--------------------------------
### Enable iOS WebView Microphone
Source: https://developer.vuplex.com/webview/iOSWebView
Enables only the microphone for an iOS WebView without enabling the camera. Additional setup steps are required as described in the documentation.
```csharp
void Awake() {
#if UNITY_IOS && !UNITY_EDITOR
iOSWebView.SetMicrophoneEnabled(true);
#endif
}
```
--------------------------------
### Create VisionOSWebView with Custom Window Options (Unity C#)
Source: https://developer.vuplex.com/webview/VisionOSWebView
Creates a VisionOSWebView within a native visionOS window, allowing for customization of the window's initial size and position using VisionOSWindowOptions. Note that size and position options require visionOS 2.0; on earlier versions, system defaults are used. This method is ideal for setting up the web view with specific layout requirements upon creation.
```csharp
#if UNITY_VISIONOS && !UNITY_EDITOR
var webView = await VisionOSWebView.CreateInWindow(
new VisionOSWindowOptions {
Size = new Vector2Int(1000, 1000),
Position = new VisionOSWindowPosition(
VisionOSWindowPositionType.Trailing,
VisionOSWindowPosition.UnityBoundedSceneID
)
}
);
// The webview has been displayed to the user in a native window,
// and now you can use IWebView APIs like LoadUrl() and LoadHtml().
webView.LoadUrl("https://vuplex.com");
// Add an event handler that destroys the webview when the user closes the window.
webView.Window.Closed += (sender, eventArgs) => {
webView.Dispose();
};
#endif
```
--------------------------------
### Resolution
Source: https://developer.vuplex.com/webview/CanvasWebViewPrefab
Gets or sets the prefab's resolution in pixels per Unity unit. You can change the resolution to make web content appear larger or smaller. The default resolution for CanvasWebViewPrefab is `1`.
```APIDOC
## GET/SET /websites/developer_vuplex/Resolution
### Description
Gets or sets the prefab's resolution in pixels per Unity unit. This affects the perceived size of web content.
### Method
GET/SET
### Endpoint
/websites/developer_vuplex/Resolution
### Parameters
#### Query Parameters
- **Resolution** (float) - Required - The desired resolution in pixels per Unity unit. Lower values make content larger, higher values make it smaller.
### Response
#### Success Response (200)
- **Resolution** (float) - The current resolution in pixels per Unity unit.
#### Important note
When running in Native 2D Mode, this field is ignored as the device's native resolution is used instead.
```
--------------------------------
### Set Rendering Enabled
Source: https://developer.vuplex.com/webview/IWebView
Enables or disables the rendering of the webview's content. This can be used to pause rendering temporarily, for example, to save resources when the webview is not visible.
```csharp
void SetRenderingEnabled(bool enabled)
```
--------------------------------
### Set WebView for Initialization
Source: https://developer.vuplex.com/webview/WebViewPrefab
Provides an existing, already initialized IWebView instance to the WebViewPrefab. This bypasses the prefab's default behavior of creating a new web view and must be called before the prefab initializes.
```csharp
void SetWebViewForInitialization(IWebView webView)
```
--------------------------------
### Handle WebViewPrefab Initialization Completion
Source: https://developer.vuplex.com/webview/WebViewPrefab
Subscribes to the Initialized event, which signals that the WebViewPrefab has completed its initialization process and its WebView property is ready for use. This is an alternative to using the async WaitUntilInitialized() method.
```csharp
EventHandler Initialized
```
--------------------------------
### Handle VisionOSWindow Closed Event
Source: https://developer.vuplex.com/webview/VisionOSWindow
This example shows how to add an event handler to the Closed event of a VisionOS window. The handler is triggered when the window is closed and in this case, disposes of the webview.
```csharp
#if UNITY_VISIONOS && !UNITY_EDITOR
var webView = await VisionOSWebView.CreateInWindow();
// Add an event handler that destroys the webview when the user closes the window.
webView.Window.Closed += (sender, eventArgs) => {
webView.Dispose();
};
#endif
```
--------------------------------
### Implementing IWithMutableAudio Interface (C#)
Source: https://developer.vuplex.com/webview/releases
Demonstrates the implementation of the `IWithMutableAudio` interface, indicating support for mutable audio features within web views. This interface is available on various platforms like Android Gecko.
```csharp
/* The following classes now implement IWithMutableAudio:
* AndroidGeckoWebView
* WebViewPrefab
* CanvasWebViewPrefab
*/
```
--------------------------------
### LoadProgressChanged
Source: https://developer.vuplex.com/webview/IWebView
Tracks the progress of a web page loading. It can indicate the start, update, finish, or failure of a page load, allowing for progress bars or loading completion detection.
```APIDOC
## LoadProgressChanged
### Description
Indicates changes in the loading status of a web page. This event can be used to detect when a page finishes loading or to implement a load progress bar.
### Method
`EventHandler LoadProgressChanged`
### Parameters
#### Event Arguments
- **Type** (ProgressChangeType) - The type of load event: `Started`, `Updated`, `Finished`, or `Failed`.
- **Progress** (float) - The progress percentage of the page load (0.0 to 1.0), only applicable for `Updated` events.
### Request Example
```csharp
await webViewPrefab.WaitUntilInitialized();
webViewPrefab.WebView.LoadProgressChanged += (sender, eventArgs) => {
Debug.Log($"Load progress changed: {eventArgs.Type}, {eventArgs.Progress}");
if (eventArgs.Type == ProgressChangeType.Finished) {
Debug.Log("The page finished loading");
}
};
```
### Important Note
For 2D WebView for WebGL, `LoadProgressChanged` only indicates `ProgressChangeType.Started` and `Finished` events. It's unable to indicate `Failed` or `Updated` events.
```
--------------------------------
### Get Raw Texture Data
Source: https://developer.vuplex.com/webview/IWebView
Retrieves the raw texture data of the webview's current content as a byte array. This can be used for custom rendering or processing of the web content.
```csharp
Task GetRawTextureData()
```
--------------------------------
### Instantiate WebViewPrefab with Existing IWebView
Source: https://developer.vuplex.com/webview/WebViewPrefab
Initializes a new WebViewPrefab using an already existing and initialized IWebView instance. This allows for sharing web views across multiple prefabs or using web views created by popup requests.
```csharp
await firstWebViewPrefab.WaitUntilInitialized();
var secondWebViewPrefab = WebViewPrefab.Instantiate(firstWebViewPrefab.WebView);
// TODO: Position secondWebViewPrefab to the location where you want to display it.
```
--------------------------------
### Get Native Android WebView Instance
Source: https://developer.vuplex.com/webview/AndroidWebView
Retrieves the underlying native android.webkit.WebView object. This allows developers to use Android-specific APIs that may not have direct C# equivalents in 3D WebView.
```csharp
AndroidJavaObject GetNativeWebView()
```
--------------------------------
### Configure WebView Initialization Options
Source: https://developer.vuplex.com/webview/WebViewOptions
WebViewOptions allows customization of WebViewPrefab initialization. Properties like 'clickWithoutStealingFocus' control focus behavior, 'disableVideo' manages iOS video fallback, and 'preferredPlugins' specifies plugin selection on platforms like Android.
```csharp
using Vuplex.WebView;
// Example usage within a Unity script
WebViewOptions options = new WebViewOptions();
// Prevent clicking from stealing focus
options.clickWithoutStealingFocus = true;
// Disable the fallback video implementation on iOS
// This option is ignored on non-iOS platforms or when Native 2D Mode is enabled.
options.disableVideo = true;
// Specify preferred plugins for Android
// If both WebPluginType.Android and WebPluginType.AndroidGecko are installed,
// this forces WebPluginType.Android to be used instead of the default.
options.preferredPlugins = new WebPluginType[] { WebPluginType.Android };
// Instantiate WebViewPrefab with custom options
// WebViewPrefab.Instantiate(options);
// Or set options for initialization
// WebViewPrefab.SetOptionsForInitialization(options);
```
--------------------------------
### Instantiate CanvasKeyboard - C#
Source: https://developer.vuplex.com/webview/CanvasKeyboard
Creates a new instance of CanvasKeyboard and configures its RectTransform properties for placement within a Canvas. This method is useful for programmatically adding a keyboard to your scene.
```csharp
var keyboard = CanvasKeyboard.Instantiate();
keyboard.transform.SetParent(canvas.transform, false);
var rectTransform = keyboard.transform as RectTransform;
rectTransform.anchoredPosition3D = Vector3.zero;
rectTransform.offsetMin = Vector2.zero;
rectTransform.offsetMax = Vector2.zero;
rectTransform.sizeDelta = new Vector2(650, 162);
```
--------------------------------
### Get Web Page Title (C#)
Source: https://developer.vuplex.com/webview/IWebView
Retrieves the title of the current web page after it has finished loading. This API may be disabled on 2D WebView for WebGL due to browser limitations.
```csharp
// Get the page's title after it finishes loading.
await webViewPrefab.WaitUntilInitialized();
await webViewPrefab.WebView.WaitForNextPageLoadToFinish();
Debug.Log("Page title: " + webViewPrefab.WebView.Title);
```
--------------------------------
### Configure WebView Initialization Options
Source: https://developer.vuplex.com/webview/WebViewPrefab
Sets specific options that influence how the WebViewPrefab creates its IWebView during initialization. This must be called before the prefab is initialized, typically right after instantiation or when activating a previously inactive prefab.
```csharp
using System;
using UnityEngine;
using Vuplex.WebView;
class SetOptions : MonoBehaviour {
// IMPORTANT: With this approach, you must set your WebViewPrefab or CanvasWebViewPrefab to inactive
// in the scene hierarchy so that this script can manually activate it. Otherwise, this
// script won't be able to call SetOptionsForInitialization() before the prefab initializes.
//
// TODO: Set this webViewPrefab field to the inactive WebViewPrefab or CanvasWebViewPrefab in your scene
// via the Editor's Inspector tab.
public BaseWebViewPrefab webViewPrefab;
void Awake() {
if (webViewPrefab.gameObject.activeInHierarchy) {
throw new Exception("The WebViewPrefab object is active in the Editor's scene view. Please set it to inactive so that this script can manually activate it.");
}
webViewPrefab.gameObject.SetActive(true);
webViewPrefab.SetOptionsForInitialization(new WebViewOptions {
preferredPlugins = new WebPluginType[] { WebPluginType.Android }
});
}
}
```
--------------------------------
### Set VisionOSWindow Fullscreen Enabled
Source: https://developer.vuplex.com/webview/VisionOSWindow
This example shows how to enable or disable the JavaScript Fullscreen API for a VisionOS webview window. The default is true, allowing web pages to use the fullscreen API.
```csharp
#if UNITY_VISIONOS && !UNITY_EDITOR
var webView = await VisionOSWebView.CreateInWindow();
// Disable the JavaScript Fullscreen API.
webView.Window.SetFullscreenEnabled(false);
#endif
```
--------------------------------
### SetOptionsForInitialization
Source: https://developer.vuplex.com/webview/CanvasWebViewPrefab
Sets WebViewOptions to configure the webview before it initializes. This must be called before the prefab initializes.
```APIDOC
## SetOptionsForInitialization
### Description
Sets options that can be used to alter the webview that the prefab creates during initialization. This method can only be called prior to when the prefab initializes (i.e. directly after instantiating it or setting it to active).
### Method
`void SetOptionsForInitialization(WebViewOptions options)`
### Parameters
#### Path Parameters
- None
#### Query Parameters
- None
#### Request Body
- **options** (WebViewOptions) - The options to apply for initialization.
### Request Example
```csharp
using System;
using UnityEngine;
using Vuplex.WebView;
class SetOptions : MonoBehaviour {
// IMPORTANT: With this approach, you must set your WebViewPrefab or CanvasWebViewPrefab to inactive
// in the scene hierarchy so that this script can manually activate it. Otherwise, this
// script won't be able to call SetOptionsForInitialization() before the prefab initializes.
//
// TODO: Set this webViewPrefab field to the inactive WebViewPrefab or CanvasWebViewPrefab in your scene
// via the Editor's Inspector tab.
public BaseWebViewPrefab webViewPrefab;
void Awake() {
if (webViewPrefab.gameObject.activeInHierarchy) {
throw new Exception("The WebViewPrefab object is active in the Editor's scene view. Please set it to inactive so that this script can manually activate it.");
}
webViewPrefab.gameObject.SetActive(true);
webViewPrefab.SetOptionsForInitialization(new WebViewOptions {
preferredPlugins = new WebPluginType[] { WebPluginType.Android }
});
}
}
```
### Response
#### Success Response (200)
- Void (no content)
#### Response Example
- None
```
--------------------------------
### CanvasWebViewPrefab Methods
Source: https://developer.vuplex.com/webview/CanvasWebViewPrefab
This section outlines the public methods available for interacting with the CanvasWebViewPrefab, including methods for screen point conversion, destruction, instantiation, and initialization.
```APIDOC
## CanvasWebViewPrefab Methods
### BrowserToScreenPoint
- **Description**: Converts a point from browser coordinates to screen coordinates.
- **Parameters**:
- **xInPixels** (int) - The X coordinate in browser pixels.
- **yInPixels** (int) - The Y coordinate in browser pixels.
- **Returns**: `Vector2` - The converted screen coordinates.
### Destroy
- **Description**: Destroys the CanvasWebViewPrefab and its associated IWebView.
### Instantiate
- **Description**: Creates a new instance of CanvasWebViewPrefab.
- **Overloads**:
- `static CanvasWebViewPrefab Instantiate(WebViewOptions options)`: Creates an instance with the specified WebViewOptions.
- `static CanvasWebViewPrefab Instantiate()`: Creates an instance with default options.
- `static CanvasWebViewPrefab Instantiate(IWebView webView)`: Creates an instance with an existing IWebView.
### SetOptionsForInitialization
- **Description**: Sets the WebViewOptions for initialization. This method should be called before `Instantiate` or `WaitUntilInitialized`.
- **Parameters**:
- **options** (WebViewOptions) - The options to use for initialization.
### SetPointerInputDetector
- **Description**: Sets a custom pointer input detector for the web view.
- **Parameters**:
- **pointerInputDetector** (IPointerInputDetector) - The custom pointer input detector.
### SetWebViewForInitialization
- **Description**: Sets an existing IWebView for initialization. This method should be called before `Instantiate` or `WaitUntilInitialized`.
- **Parameters**:
- **webView** (IWebView) - The IWebView to use for initialization.
### WaitUntilInitialized
- **Description**: Waits until the CanvasWebViewPrefab has finished initializing.
- **Returns**: `Task` - A task that completes when initialization is finished.
```
--------------------------------
### Handle Standalone Browser Process Failure
Source: https://developer.vuplex.com/webview/StandaloneWebView
Subscribes to the BrowserProcessFailed event to log errors when the Chromium browser process fails to start or crashes. This is specific to standalone builds (UNITY_STANDALONE or UNITY_EDITOR).
```csharp
void Awake() {
#if UNITY_STANDALONE || UNITY_EDITOR
StandaloneWebView.BrowserProcessFailed += (sender, eventArgs) => {
Debug.Log("3D WebView's Chromium browser process failed with the following error message: " + eventArgs.ErrorMessage);
};
#endif
}
```
--------------------------------
### Init
Source: https://developer.vuplex.com/webview/IWebView
Asynchronously initializes the webview with the given dimensions in pixels. This method is only needed when creating an IWebView directly, not when using prefabs.
```APIDOC
## Init
### Description
Asynchronously initializes the webview with the given the dimensions in pixels. Note that you don't need to call this method if you're using one of the prefabs, like WebViewPrefab. You only need to call Init() if you create an IWebView directly with Web.CreateWebView(). Also, this method's signature was updated in 3D WebView v4.
### Method
POST
### Endpoint
/websites/developer_vuplex/Init
### Parameters
#### Query Parameters
- None
#### Request Body
- **width** (int) - The width of the webview in pixels.
- **height** (int) - The height of the webview in pixels.
### Request Example
```csharp
// Example usage when creating IWebView directly:
// var webView = Web.CreateWebView();
// await webView.Init(1024, 768);
```
### Response
#### Success Response (200)
- **None**
```
--------------------------------
### Get Web Page URL (C#)
Source: https://developer.vuplex.com/webview/IWebView
Retrieves the current URL of the loaded web page. Similar to the title API, this may be disabled on 2D WebView for WebGL due to browser limitations.
```csharp
// Get the page's URL after it finishes loading.
await webViewPrefab.WaitUntilInitialized();
await webViewPrefab.WebView.WaitForNextPageLoadToFinish();
Debug.Log("Page URL: " + webViewPrefab.WebView.Url);
```