Skip to main content
Version: 20 Mar 2024

MLWebView

NameSpace: MagicLeap

API for MLWebView that allows an application to instantiate a hardware accelerated WebView and interact with it(via "mouse" and "keyboard" events). More...

Inherits from:
MLAPIBase

Detailed Description

public class MLWebView : MLAPIBase 

Details*

MLWebView class exposes static functions that allows an application to instantiate a hardware accelerated WebView and interact with it(via "mouse" and "keyboard" events).


Public Fields

AcceptPopup

Flag to indicate if the application accepts the popup


public bool AcceptPopup = false { get; set; }


IgnoreCertificateError

Flag to indicate if urls issuing certificate errors should be loaded or not


public bool IgnoreCertificateError { get; set; }


WebViewHandle

Retrieves the assigned web view handle.


public ulong WebViewHandle { get; set; }

Returns: The assigned web view handle, MagicLeapNativeBindings.InvalidHandle if it has not been created.


Public Methods

bool CanGoBack

Checks if the "Back" action is currently valid.

public bool CanGoBack()

Returns: True if can use the "Back" action.


bool CanGoForward

Checks if the "Forward" action is currently valid.

public bool CanGoForward()

Returns: True if can use the "Forward" action.


MLResult ClearCache

Clear the webview cache.

public MLResult ClearCache()

Returns: MLResult.Code.Ok if cache cleared successfully

MLResult.Code.InvalidParam if its unable to find the specified MLWebView .

MLResult.Code.UnspecifiedFailure if clearing cache failed due to an internal error.


MLWebView Create

Create a MLWebView. The MLWebView will be ready to use once this function returns with MLResult_OK.

public static MLWebView Create(
uint width,
uint height,
bool isPopup =false,
ulong popupId =0
)

Parameters

TypeNameDescription
uintwidthWidth of the WebView in pixels.
uintheightHeight of the WebView in pixels.
boolisPopup
ulongpopupId

Returns: MLWebView instance if creation was successful, null otherwise.


MLResult Destroy

Destroy a MLWebView. The MLWebView will be terminated by this function call and the shall no longer be valid.

public MLResult Destroy()

Returns: MLResult.Code.Ok if was destroyed successfully.

MLResult.Code.UnspecifiedFailure if an error occurred destroying the MLWebView.

MLResult.Code.InvalidParam if its unable to find the specified MLWebView .


Vector2Int GetScrollOffset

Get the scroll offset of the webview.

public Vector2Int GetScrollOffset()

Returns: Vector2Int representing the horizontal and vertical offset of the webview, in pixels.


Vector2Int GetScrollSize

Get the entire scrollable size of the webview. This should be typically called afer OnLoadEnd to determine the scollable size of the main frame of the loaded page.Some pages might dynamically resize and this should be called before each frame draw to correctly determine the scrollable size of the webview.

public Vector2Int GetScrollSize()

Returns: Vector2Int representing the entire width and height of the webview, in pixels.


string GetURL

Get the current URL.

public string GetURL()

Returns: Current URL.


double GetZoomFactor

Get the current zoom factor. The default zoom factor is 1.0.

public double GetZoomFactor()

Returns: Current numeric value for zoom factor.


MLResult GoBack

Trigger a "Back" action in the MLWebView. Query #MLWebViewCanGoBack before calling this method. If there is no valid page to go back to, this method will be no-op.

public MLResult GoBack()

Returns: MLResult.Code.Ok if WebView Back action was initiated or cannot go back any further.

MLResult.Code.InvalidParam if its unable to find the specified MLWebView .


MLResult GoForward

Trigger a "Forward" action in the MLWebView. Query MLWebViewCanGoForward before calling this method. If there is no valid page to go forward to, this method will be no-op.

public MLResult GoForward()

Returns: MLResult.Code.Ok if WebView Forward action was initiated or cannot go forward any further.

MLResult.Code.InvalidParam if its unable to find the specified MLWebView .


MLResult GoTo

Go to a URL with the specified MLWebView. Note that success with this call only indicates that a load will be attempted. Caller can be notified about issues loading the URL via the event r on_load_error.

public MLResult GoTo(
string url
)

Parameters

TypeNameDescription
stringurlURL that will be loaded.

Returns: MLResult.Code.Ok if WebView is attempting to load the specified URL.

MLResult.Code.InvalidParam if its unable to find the specified MLWebView .


MLResult InjectChar

Sends a printable char keyboard event to MLWebView.

public MLResult InjectChar(
char charUtf
)

Parameters

TypeNameDescription
charcharUtf32printable char utf code

Returns: MLResult.Code.Ok if key event was injected.

MLResult.Code.InvalidParam if its unable to find the specified MLWebView .


MLResult InjectKeyDown

Sends a key down/pressed event to MLWebView.

public MLResult InjectKeyDown(
MLWebView.KeyCode keyCode,
uint modifierMask
)

Parameters

TypeNameDescription
MLWebView.KeyCodekeyCodeMLWebView.KeyCode.
uintmodifierMaskShould be one or combination of MLWebView.EventFlags.

Returns: MLResult.Code.Ok if key event was injected.

MLResult.Code.InvalidParam if its unable to find the specified MLWebView .


MLResult InjectKeyUp

Sends a key up/release event to MLWebView.

public MLResult InjectKeyUp(
MLWebView.KeyCode keyCode,
uint modifierMask
)

Parameters

TypeNameDescription
MLWebView.KeyCodekeyCodeMLWebView.KeyCode.
uintmodifierMaskShould be one or combination of MLWebView.EventFlags.

Returns: MLResult.Code.Ok if key event was injected.

MLResult.Code.InvalidParam if its unable to find the specified MLWebView .


MLResult InjectMouseButtonDown

Sends a mouse button down/pressed event on a specific location on screen.

public MLResult InjectMouseButtonDown(
uint xPosition,
uint yPosition,
EventFlags modifiers
)

Parameters

TypeNameDescription
uintxPositionHorizontal position of the cursor.
uintyPositionVertical position of the cursor.
EventFlagsmodifiersShould be one or combination of EventFlags.

Returns: MLResult.Code.Ok if successful.

MLResult.Code.InvalidParam if its unable to find the specified MLWebView .


MLResult InjectMouseButtonUp

Sends a mouse button up/released event on a specific location on screen.

public MLResult InjectMouseButtonUp(
uint xPosition,
uint yPosition,
EventFlags modifiers
)

Parameters

TypeNameDescription
uintxPositionHorizontal position of the cursor.
uintyPositionVertical position of the cursor.
EventFlagsmodifiersShould be one or combination of EventFlags.

Returns: MLResult.Code.Ok if successful.

MLResult.Code.InvalidParam if its unable to find the specified MLWebView .


MLResult InjectMouseMove

Moves the WebView mouse.

public MLResult InjectMouseMove(
uint xPosition,
uint yPosition,
EventFlags modifiers
)

Parameters

TypeNameDescription
uintxPositionHorizontal position of the cursor.
uintyPositionVertical position of the cursor.
EventFlagsmodifiersShould be one or combination of EventFlags.

Returns: MLResult.Code.Ok if internal mouse was moved.

MLResult.Code.InvalidParam if its unable to find the specified MLWebView .


delegate void OnBeforePopupDelegate

The delegate for the webview before popup event.

public delegate void OnBeforePopupDelegate(
MLWebView webView,
string url,
bool popupAccepted
)

Parameters

TypeNameDescription
MLWebViewwebViewThe MLWebView associated with this callback.
stringurlThe URL for the popup to load.
boolpopupAccepted

delegate void OnBeforeResourceLoadDelegate

The delegate for the before reasource loaded event.

public delegate void OnBeforeResourceLoadDelegate(
MLWebView webView,
string resourceURL
)

Parameters

TypeNameDescription
MLWebViewwebViewThe MLWebView associated with this callback.
stringresourceURLThe url of the resource about to be loaded.

delegate void OnCertificateErrorDelegate

The delegate for the certificate error event.

public delegate void OnCertificateErrorDelegate(
MLWebView webView,
int errorCode,
string url,
string errorMessage,
string details,
bool certificateErrorIgnored
)

Parameters

TypeNameDescription
MLWebViewwebViewThe MLWebView associated with this callback.
interrorCodeError code for ssl error.
stringurlThe url associated to the certificate error.
stringerrorMessageCertificate error short description.
stringdetailsCertificate error details.
boolcertificateErrorIgnored

delegate void OnDestroyDelegate

The delegate for the webview destroy event.

public delegate void OnDestroyDelegate(
MLWebView webView
)

Parameters

TypeNameDescription
MLWebViewwebViewThe MLWebView associated with this callback.

delegate void OnKeyboardDismissDelegate

The delegate for the keyboard dismiss event.

public delegate void OnKeyboardDismissDelegate(
MLWebView webView
)

Parameters

TypeNameDescription
MLWebViewwebViewThe MLWebView associated with this callback.

delegate void OnLoadEndDelegate

The delegate for the reasource loaded event.

public delegate void OnLoadEndDelegate(
MLWebView webView,
bool isMainFrame,
int httpStatusCode
)

Parameters

TypeNameDescription
MLWebViewwebViewThe MLWebView associated with this callback.
boolisMainFrameWhether this event was for the main frame.
inthttpStatusCodeThe standard http status code.

delegate void OnLoadErrorDelegate

The delegate for the reasource load error event.

public delegate void OnLoadErrorDelegate(
MLWebView webView,
bool isMainFrame,
int httpStatusCode,
string errorStr,
string failedUrl
)

Parameters

TypeNameDescription
MLWebViewwebViewThe MLWebView associated with this callback.
boolisMainFrameTrue if this event was for the main frame.
inthttpStatusCodeHttp status code for the URL load failure.
stringerrorStrThe stringified version of the error code.
stringfailedUrlThe url that caused the load error.

delegate void OnPopupClosedDelegate

The delegate fpr the webview popup closed event.

public delegate void OnPopupClosedDelegate(
MLWebView webView,
ulong handle
)

Parameters

TypeNameDescription
MLWebViewwebViewThe MLWebView associated with this callback.
ulonghandleThe webview handle of the popup being closed.

delegate void OnPopupOpenedDelegate

The delegate for the webview popup opened event.

public delegate void OnPopupOpenedDelegate(
MLWebView webView,
ulong popupID,
string url
)

Parameters

TypeNameDescription
MLWebViewwebViewThe MLWebView associated with this callback.
ulongpopupIDThe ID of the popup.
stringurlThe URL associated with the popup.

delegate void OnServiceConnectedDelegate

The delegate for the webview service connected event.

public delegate void OnServiceConnectedDelegate(
MLWebView webView
)

Parameters

TypeNameDescription
MLWebViewwebViewThe MLWebView associated with this callback.

delegate void OnServiceDisconnectedDelegate

The delegate for the webview service disconnected event.

public delegate void OnServiceDisconnectedDelegate(
MLWebView webView
)

Parameters

TypeNameDescription
MLWebViewwebViewThe MLWebView associated with this callback.

delegate void OnServiceFailedDelegate

The delegate for the webview service failed event.

public delegate void OnServiceFailedDelegate(
MLWebView webView,
MLResult result
)

Parameters

TypeNameDescription
MLWebViewwebViewThe MLWebView associated with this callback.
MLResultresultThe MLResult code associated with the failure.

delegate void OnShowKeyboardDelegate

The delegate for the keyboard show event.

public delegate void OnShowKeyboardDelegate(
MLWebView webView,
InputFieldData keyboardShowData
)

Parameters

TypeNameDescription
MLWebViewwebViewThe MLWebView associated with this callback.
InputFieldDatakeyboardShowDataData about the clicked input field.

MLResult Pause

Pause the webview. Call MLWebViewResume to resume. This method provides a multiple pause types to the webview.

public MLResult Pause(
PauseType pauseType
)

Parameters

TypeNameDescription
PauseTypepauseTypeThe type of pause to be used.

Returns: MLResult.Code.Ok if paused successfully.

MLResult.Code.InvalidParam if its unable to find the specified MLWebView handle or PauseType value.

MLResult.Code.UnspecifiedFailure if failed due to an internal error.

MLResult.Code.Pending if the MLWebView handle is not ready to use. See an asynchronous mode of MLWebViewCreate.


MLResult Reload

Trigger a "Reload" action in the MLWebView.

public MLResult Reload()

Returns: MLResult.Code.Ok if WebView Reload action was initiated.

MLResult.Code.InvalidParam if its unable to find the specified MLWebView .


MLResult RemoveAllCookies

Remove all webview cookies.

public MLResult RemoveAllCookies()

Returns: MLResult.Code.Ok if all cookies removed successfully.

MLResult.Code.InvalidParam if its unable to find the specified MLWebView .

MLResult.Code.UnspecifiedFailure if removing all cookies failed due to an internal error.


MLResult ResetZoom

Reset zoom level to 1.0.

public MLResult ResetZoom()

Returns: MLResult.Code.Ok if MLWebView zoom was reset.

MLResult.Code.InvalidParam if its unable to find the specified MLWebView .

MLResult.Code.UnspecifiedFailure if it failed to reset zoom due to an internal error.


MLResult Resume

Resumes a webview after a previous call of Pause. Resume webview to the normal operation for all webview pause types.

public MLResult Resume()

Parameters

TypeNameDescription
handleThe webview being accessed.

Returns: MLResult.Code.Ok if resumed successfully.

MLResult.Code.IllegalState if WebView was paused. See MLWebViewPause.

MLResult.Code.InvalidParam if its unable to find the specified MLWebView handle.

MLResult.Code.UnspecifiedFailure if failed due to an internal error.

MLResult.Code.Pending if the MLWebView handle is not ready to use. See an asynchronous mode of MLWebViewCreate.


MLResult ScrollBy

Triggers a mouse "Scroll" event.

public MLResult ScrollBy(
uint xPixels,
uint yPixels
)

Parameters

TypeNameDescription
uintxPixelsThe number of pixels to scroll on the x axis.
uintyPixelsThe number of pixels to scroll on the y axis.

Returns: MLResult.Code.Ok if MLWebView was scrolled.

MLResult.Code.InvalidParam if its unable to find the specified MLWebView .


MLResult ZoomIn

Zoom in one level.

public MLResult ZoomIn()

Returns: MLResult.Code.Ok if MLWebView zoomed in.

MLResult.Code.InvalidParam if its unable to find the specified MLWebView .

MLResult.Code.WebViewResultZoomLimitReached if cannot zoom in any further.

MLResult.Code.UnspecifiedFailure if it failed to reset zoom due to an internal error.


MLResult ZoomOut

Zoom out one level.

public MLResult ZoomOut()

Returns: MLResult.Code.Ok if MLWebView zoomed out.

MLResult.Code.InvalidParam if its unable to find the specified MLWebView .

MLResult.Code.WebViewResultZoomLimitReached if cannot zoom out any further.

MLResult.Code.UnspecifiedFailure if it failed to reset zoom due to an internal error.


Public Events

OnBeforePopup

Event raised when WebView checks if a URL is OK to load in a popup.

public OnBeforePopupDelegate OnBeforePopup()

OnBeforeResourceLoaded

Event raised just before resources are loaded.

public OnBeforeResourceLoadDelegate OnBeforeResourceLoaded()

OnCertificateErrorLoaded

Event raised when there was an error during certification loading.

public OnCertificateErrorDelegate OnCertificateErrorLoaded()

OnErrorLoaded

Event raised when there was an error during loading.

public OnLoadErrorDelegate OnErrorLoaded()

OnKeyboardDismissed

Event rasied if Keyboard should be dismissed.

public OnKeyboardDismissDelegate OnKeyboardDismissed()

OnKeyboardShown

Event raised if user clicked inputfield and keyboard should be displayed.

public OnShowKeyboardDelegate OnKeyboardShown()

OnLoadEnded

Event raised when resources finish loading.

public OnLoadEndDelegate OnLoadEnded()

OnPopupClosed

Event raised when Webview is closing a popup.

public OnPopupClosedDelegate OnPopupClosed()

OnPopupOpened

Event raised when WebView opened a popup.

public OnPopupOpenedDelegate OnPopupOpened()

OnServiceConnected

Event raised when WebView service is connected.

public OnServiceConnectedDelegate OnServiceConnected()

OnServiceDisconnected

Event raised when WebView service is disconnected.

public OnServiceDisconnectedDelegate OnServiceDisconnected()

OnServiceFailed

Event raised when WebView service fails to connect.

public OnServiceFailedDelegate OnServiceFailed()

OnWebViewDestroyed

Event raised when WebView is destroyed.

public OnDestroyDelegate OnWebViewDestroyed()

Public Enums

EventFlags

Flags to set special key states during input.

EnumeratorValueDescription
None0No flag is applied.
CapsLockOn1 << 0Caps Lock is on.
ShiftDown1 << 1Shift is pressed.
ControlDown1 << 2Control is pressed.
AltDown1 << 3Alt is pressed.
LeftMouseButton1 << 4Left mouse button is pressed.
MiddleMouseButton1 << 5Middle mouse button is pressed.
RightMouseButton1 << 6Right mouse button is pressed.
CommandDown1 << 7Command key is pressed.
NumLockOn1 << 8NumLock is on.
IsKeyPad1 << 9Was key struck on KeyPad.
IsLeft1 << 10Is left key.
IsRight1 << 11Is right key.
AltGRDown1 << 12AltGR is pressed.

KeyCode

Enums for all possible ML Key Codes.

EnumeratorValueDescription
Unknown0
Home3
Back4
DpadLeft21
DpadRight22
Delete67
Focus80
Plus81
Menu82
Forward125
Trigger500
Capture501
Bumper502
Reality503
Battery504
MLBack508
HomeTapMLBack
HomeMediumTap509
Popple510
MouseLeft511
MouseRight512
MouseWheel513
MouseExtra514
MouseSide515
VkbCancel1001
VkbSubmit1002
VkbPrevious1003
VkbNext1004
VkbClear1005
VkbClose1006
VkbCustom11007
VkbCustom21008
VkbCustom31009
VkbCustom41010
VkbHidePassword1012
VkbShowPassword1013

PauseType

The type of the webview pause.

EnumeratorValueDescription
MultiMediaPause all multimedia activities of the webview.
TimersPause javascript timers of the webview.
DiscardPause and discard the webview rendering process. But keep alive the MLWebView handle.

TextInputFlags

Flags related to a text entry field passed when on_show_keyboard is called.

EnumeratorValueDescription
None0Nonne of flasg are applied.
AutocompleteOn1 << 0Autocompletion is on.
AutocompleteOff1 << 1Autocompletion is off.
AutocorrectOn1 << 2Autocorrection is on.
AutocorrectOff1 << 3Autocorrection is off.
SpellcheckOn1 << 4Spellcheck is on.
SpellcheckOff1 << 5Spellcheck is of.
AutocapitalizeNone1 << 6Autocapitalize is off.
AutocapitalizeCharacters1 << 7Autocapitalize characters.
AutocapitalizeWords1 << 8Autocapitalize words.
AutocapitalizeSentences1 << 9Autocapitalize sentences.
HaveNextFocusableElement1 << 10Have next focusable element.
HavePreviousFocusableElement1 << 11Have previous focusable element.
HasBeenPasswordField1 << 12has been a password field.

TextInputType

The type of text entry selected when onShowKeyboard is called.

EnumeratorValueDescription
NoneNone.
TextText.
PasswordPassword.
SearchSearch.
EmailEmail.
NumberNumber
TelephoneTelephone.
URLURL.
DateDate.
DateTimeDate Time.
DateTimeLocalDate Time Local.
MonthMonth.
TimeTime.
WeekWeek.
TextAreaText Area.
ContentEditableContent Editable.
DateTimeFieldDate Time Field.