Skip to content
Francisco Dias edited this page Mar 26, 2026 · 5 revisions

WebView

This extension allows Android and iOS developers as well as developers of Windows, macOS and Linux to make use of the WebView to display site URLs directly from inside their game. The WebView extension can also be used to perform OAuth2 authentication from within your game.

When specifying a URL to open, you should make sure to always include the protocol part (e.g., "http://", "https://", "file://", etc.).

Note

You can only have one WebView window open at a given time.

Guides

These are the guides for the WebView extension:

Functions

The following functions are provided to manipulate the WebView:

Constants

The following enumerations are provided to configure the WebView:



Back To Top

webview_open_url

This function opens the given URL in a WebView.

Note

This function will destroy all buttons currently on the WebView if a URL is already open.


Syntax:

webview_open_url(url=undefined)
Argument Type Description
url String The URL to open



Returns:

N/A


Example:

webview_open_url("https://manual.gamemaker.io");

This code opens a URL in the WebView window.




Back To Top

webview_hide

This function hides the WebView window.


Syntax:

webview_hide()



Returns:

N/A


Example:

webview_hide();

This code hides the WebView window.




Back To Top

webview_show

This function shows the WebView window, setting it to visible.

Note

This function requests the WebView to be made visible. webview_is_visible will not immediately return true after calling this function.


Syntax:

webview_show()



Returns:

N/A


Example:

webview_show();

This code brings up the WebView window.




Back To Top

webview_close

This function closes the WebView window.


Syntax:

webview_close()



Returns:

N/A


Example:

webview_close();

This code closes the WebView.




Back To Top

webview_load_html

This function loads custom HTML in the WebView.


Syntax:

webview_load_html(html=undefined)
Argument Type Description
html String The HTML to load



Returns:

N/A


Example:

var _html = @"
<html>
  <head>
    <title>Page Title</title>
  </head>
  <body>
  <h1>Information</h1>
    <p>This is information about the game.</p>
  </body>
</html>";
webview_load_html(_html);

This code loads the HTML in the WebView.




Back To Top

webview_load_local

This function loads a page from a local file in the WebView.


Syntax:

webview_load_local(path=undefined)
Argument Type Description
path String The path to the local file



Returns:

N/A


Example:

webview_load_local("instructions.htm");

This code loads a local page.




Back To Top

webview_load_blank

This function loads a blank page.


Syntax:

webview_load_blank()



Returns:

N/A


Example:

webview_load_blank();

This code loads a blank page.




Back To Top

webview_load_youtube

This function loads a YouTube video in the WebView.


Syntax:

webview_load_youtube(uid=undefined)
Argument Type Description
uid String The ID of the video



Returns:

N/A




Back To Top

webview_load_no_internet

This function loads a "no internet" page.


Syntax:

webview_load_no_internet()



Returns:

N/A


Example:

webview_load_no_internet();

This code loads a "no internet" page.




Back To Top

webview_set_start_mode

This function sets the start mode for the WebView.


Syntax:

webview_set_start_mode(mode)
Argument Type Description
mode WebViewStartMode The mode to use



Returns:

N/A


Example:

webview_set_start_mode(WebViewStartMode.Visible);

This code sets the WebView to start visible.




Back To Top

webview_set_borderless

This function sets whether the WebView window should have a border or not. The function should be called after opening or loading a page, calls before that will have no effect.

Note

Borderless functionality only works on desktop targets. On mobile the WebView is always displayed borderless and fullscreen.


Syntax:

webview_set_borderless(on)
Argument Type Description
on Boolean Whether to display borderless or not



Returns:

N/A


Example:

webview_open_url("https://www.google.com");
webview_set_borderless(true);

This code opens a URL and then sets the WebView window to display without the window border.




Back To Top

webview_get_url

This function gets the WebView's URL.


Syntax:

webview_get_url()



Returns:

String


Example:

var _url = webview_get_url();
show_debug_message(_url);

This code gets the WebView URL and outputs it in a debug message.




Back To Top

webview_get_title

This function gets the title of the page loaded in the WebView.


Syntax:

webview_get_title()



Returns:

String


Example:

var _title = webview_get_title();
show_debug_message(_title);

This code gets the current page title and outputs it in a debug message.




Back To Top

webview_is_loading

This function returns if the WebView is loading.


Syntax:

webview_is_loading()



Returns:

Boolean


Example:

/// Draw GUI Event
var _loading = webview_is_loading();
draw_text(5, 5, $"Loading: {_loading}");

This code draws a text in the Draw GUI event to indicate if the WebView is loading or not.




Back To Top

webview_is_running

This function returns if the WebView is running.


Syntax:

webview_is_running()



Returns:

Boolean


Example:

/// Draw GUI Event
var _running = webview_is_running();
draw_text(5, 5, $"Running: {_running}");

This code draws a text in the Draw GUI event to indicate if the WebView is running or not.




Back To Top

webview_is_visible

This function returns if the WebView is visible.


Syntax:

webview_is_visible()



Returns:

Boolean


Example:

var _visible = webview_is_visible();

This code gets the visibility of the WebView.




Back To Top

webview_get_body

This function gets the body HTML contents, i.e. the inner HTML, of the WebView.

The body contents will be valid after the page has finished loading and will be updated after that to account for dynamic changes to the page. Subsequent calls to this function will reflect this.

Note

The contents are returned as a Base64 encoded string if the page was loaded using webview_load_html.


Syntax:

webview_get_body()



Returns:

String


Example:

var _body_html = webview_get_body();

This code gets the current contents of the body of the WebView.




Back To Top

webview_get_params

This function gets the query string part of the WebView's URL, for example "field1=value1&field2=value2".


Syntax:

webview_get_params()



Returns:

String


Example:

var _query = webview_get_params();
show_debug_message($"Parameters: {_query}");

This code gets the query string and outputs it in a debug message.




Back To Top

webview_allow_swipe_refresh

This function sets whether to allow swipe refresh of the page in the WebView.

Note

This functionality is not supported on the Desktop targets.


Syntax:

webview_allow_swipe_refresh(allow)
Argument Type Description
allow Boolean Whether to allow swipe refresh or not



Returns:

N/A


Example:

webview_allow_swipe_refresh(true);

This code sets the WebView to allow a swipe refresh of the page.




Back To Top

webview_eval_js

This function evaluates the JavaScript code passed in the parameter.

Note

You can use the gm_post() function to post custom data that will be returned in the callback. [!WARNING]

Functions starting with __ are used internally and should not be used. [!WARNING]

The WebView extension doesn't perform any security checks on the code that you pass it.


Syntax:

webview_eval_js(js=undefined)
Argument Type Description
js String The string containing the JavaScript code to evaluate



Returns:

N/A


Example:

var _js = "alert('Hello World from GameMaker!');";
webview_eval_js(_js);

webview_eval_js("gm_post('Hello World from GameMaker!')");

This code calls the function to show a message in a JavaScript alert and also posts the same message using gm_post().




Back To Top

webview_set_js_callback

This function sets the JavaScript callback function.

This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Callback.


Syntax:

webview_set_js_callback(cb=undefined)
Argument Type Description
cb Function The callback function to use, or undefined to unset



Returns:

N/A


Triggers:

Callback

This callback is triggered when the page title changes.

Key Type Description
event_type WebViewJavaScriptEvent The constant WebViewJavaScriptEvent.OnTitleChange

This callback is triggered when the page body changes.

Key Type Description
event_type WebViewJavaScriptEvent The constant WebViewJavaScriptEvent.OnBodyChange

This callback is triggered when the page URL changes.

Key Type Description
event_type WebViewJavaScriptEvent The constant WebViewJavaScriptEvent.OnUrlChange

This callback is triggered when a button was pressed.

Key Type Description
event_type WebViewJavaScriptEvent The constant WebViewJavaScriptEvent.OnButtonPress
payload Real The button handle

This callback is triggered when the page starts loading.

Key Type Description
event_type WebViewJavaScriptEvent The constant WebViewJavaScriptEvent.OnPageLoadStart

This callback is triggered when the page finishes loading.

Key Type Description
event_type WebViewJavaScriptEvent The constant WebViewJavaScriptEvent.OnPageLoadEnd

This callback is triggered after a custom post.

Key Type Description
event_type WebViewJavaScriptEvent The constant WebViewJavaScriptEvent.OnCustomPost
payload String A JSON-formatted string containing an array with the parameters passed to gm_post() (see webview_eval_js)

Example:

webview_set_js_callback(function(_event_type, _payload) {
    if (_event_type == WebViewJavaScriptEvent.OnCustomPost) {
        show_debug_message("Post Parameters Received:");
        var _params = json_parse(_payload);
        array_foreach(_params, show_debug_message);
    } else {
        show_debug_message("JavaScript Callback!");
    }
});

This code sets a JavaScript callback function that outputs a debug message containing the parameters passed in case of a custom post event, or a short debug message for any other event.




Back To Top

webview_button_create

This function creates a button on the WebView. Buttons need to be created after opening a window.

Note

Buttons will not work when you navigate to pages that contain pre-injected iframes. [!NOTE]

Sprites cannot be passed as an asset directly. You can save a sprite using sprite_save and pass the path to the created file with a type of WebViewButtonAssetType.FilePath or pass the image as Base64 data (see the second example on the buffer_base64_encode page) with a type of WebViewButtonAssetType.Base64Data. To load from the save area, the path needs to be prefixed with game_save_id.


Syntax:

webview_button_create(size_dp, gravity, asset_type=undefined, asset=undefined)
Argument Type Description
size_dp Real The size of the button in dp
gravity Real A bitmask of gravity constants (WebViewButtonGravity)
asset_type WebViewButtonAssetType The type of asset referred to in the asset parameter
asset String The path to the image asset (in case of file path) or its contents (in case of Base64 data or raw HTML)



Returns:

Real


Example:

button1 = webview_button_create(48, WebViewButtonGravity.Top|WebViewButtonGravity.Left);
button2 = webview_button_create(48, WebViewButtonGravity.Bottom|WebViewButtonGravity.Right, WebViewButtonAssetType.FilePath, "my_custom_button.png");
button3 = webview_button_create(48, WebViewButtonGravity.Bottom|WebViewButtonGravity.Left, WebViewButtonAssetType.RawData, "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzAwIiBoZWlnaHQ9IjEzMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iMjAwIiBoZWlnaHQ9IjEwMCIgeD0iMTAiIHk9IjEwIiByeD0iMjAiIHJ5PSIyMCIgZmlsbD0iYmx1ZSIgLz48L3N2Zz4=");

This code creates a few buttons on the WebView, each using a different asset type for the button.




Back To Top

webview_button_destroy

This function destroys the given button.


Syntax:

webview_button_destroy(handle)
Argument Type Description
handle Real The button handle



Returns:

N/A


Example:

webview_button_destroy(button1);

This code destroys a previously created button.




Back To Top

webview_button_destroy_all

This function destroys all buttons currently on the WebView.


Syntax:

webview_button_destroy_all()



Returns:

N/A


Example:

webview_button_destroy_all();

This code destroys all previously created buttons.




Back To Top

webview_button_set_alpha

This function sets the alpha value of the given button.


Syntax:

webview_button_set_alpha(handle, alpha)
Argument Type Description
handle Real The button handle
alpha Real The alpha value (a value from 0 (fully transparent) to 1 (fully opaque))



Returns:

N/A


Example:

webview_button_set_alpha(button1, 0.5);

This code sets a button's alpha to 0.5.




Back To Top

webview_button_set_auto_close

This function sets whether the given button closes the WebView window.


Syntax:

webview_button_set_auto_close(handle, flag)
Argument Type Description
handle Real The button handle
flag Boolean Whether the button closes the WebView window or not



Returns:

N/A


Example:

webview_button_set_auto_close(button2, true);

This code sets a button to auto close the WebView window.




Back To Top

webview_button_set_margins

This function sets the margins for the given button.

Note

Margins can be different for each button.


Syntax:

webview_button_set_margins(handle, left, top, right, bottom)
Argument Type Description
handle Real The button handle
left Real The left margin
top Real The top margin
right Real The right margin
bottom Real The bottom margin



Returns:

N/A


Example:

webview_button_set_margins(button1, 48, 12, 48, 12);

This code sets a button's margins to 48 units horizontally and 12 units vertically.




Back To Top

webview_button_set_size

This function sets the size of the given button.


Syntax:

webview_button_set_size(handle, size_dp)
Argument Type Description
handle Real The button handle
size_dp Real The button's new size in dp



Returns:

N/A


Example:

webview_button_set_size(button1, 100);

This code sets the button's size to 100.




Back To Top

webview_button_set_gravity

This function sets the gravity for the given button.


Syntax:

webview_button_set_gravity(handle, gravity)
Argument Type Description
handle Real The button handle
gravity Real A bitwise OR of the constants to set (WebViewButtonGravity)



Returns:

N/A


Example:

webview_button_set_gravity(button2, WebViewButtonGravity.Top|WebViewButtonGravity.Right);



Back To Top

webview_button_set_position

This function sets the position for the given button.


Syntax:

webview_button_set_position(handle, x_dp, y_dp)
Argument Type Description
handle Real The button handle
x_dp Real The x position in dp
y_dp Real The y position in dp



Returns:

N/A


Example:

webview_button_set_position(button1, 200, 200);

This code sets a button's position to (200, 200).




Back To Top

webview_button_set_visible

This function sets whether the given button is visible or not.


Syntax:

webview_button_set_visible(handle, visible)
Argument Type Description
handle Real The button handle
visible Boolean Whether the button should be visible or not



Returns:

N/A


Example:

webview_button_set_visible(button1, false);

This code sets a button invisible.




Back To Top

webview_button_set_asset

This function sets the image asset to be used for the given button.

Note

Sprites cannot be passed as an asset directly. You can save a sprite using sprite_save and pass the path to the created file with a type of WebViewButtonAssetType.FilePath or pass the image as Base64 data (see the second example on the buffer_base64_encode page) with a type of WebViewButtonAssetType.Base64Data. To load from the save area, the path needs to be prefixed with game_save_id.


Syntax:

webview_button_set_asset(handle, asset_type, asset=undefined)
Argument Type Description
handle Real The button handle
asset_type WebViewButtonAssetType The type of asset referred to in the asset parameter
asset String The path to the image asset (in case of file path) or its contents (in case of Base64 data or raw HTML)



Returns:

N/A


Example:

webview_button_set_asset(button2, WebViewButtonAssetType.FilePath, "my_custom_button.png");

This code sets the asset for a button to an image stored in the given filepath.




Back To Top

webview_button_set_callback

This function sets the callback function to trigger for the button referred to by the given handle.


Syntax:

webview_button_set_callback(handle, callback=undefined)
Argument Type Description
handle Real The button handle
callback Function The function to call for this button on callback



Returns:

N/A


Example:

webview_button_set_callback(button3, func);

This code sets the GML callback function to be called when the button is clicked.




Back To Top

webview_shutdown


Syntax:

webview_shutdown()



Returns:

N/A




Back To Top

WebViewStartMode

This enumeration contains the modes in which the WebView can be started.

These constants are referenced by the following functions:


Member Description
Hidden The WebView is hidden.
Visible The WebView is visible.


Back To Top

WebViewJavaScriptEvent

This enumeration contains the types of JavaScript callback.

These constants are referenced by the following functions:


Member Description
OnUrlChange The page URL changed.
OnBodyChange The page body changed.
OnTitleChange The page title changed.
OnButtonPress A button was pressed.
OnPageLoadStart The page has started loading.
OnPageLoadEnd The page has finished loading.
OnCustomPost A custom message was posted.


Back To Top

WebViewButtonAssetType

This enumeration contains the possible asset types for a WebView button.

These constants are referenced by the following functions:


Member Description
DefaultIcon The default icon is used.
FilePath The button image is taken from a file.
Base64Data The button image is taken from Base64 data.
RawData The button image consists of raw data passed as a data URL to the image tag's src attribute.


Back To Top

WebViewButtonGravity

This enumeration holds the possible values for the button gravity. These constants can be joined together using the boolean "or" operator |.


Member Description
Left Left
Right Right
Top Top
Bottom Bottom
Start Start
End End
CenterHorizontal Center Horizontally
CenterVertical Center Vertically
Center Center