Table of Contents

Class JavaScriptBridge

Singleton that connects the engine with the browser's JavaScript context in Web export.

Inheritance
JavaScriptBridge

Remarks

The JavaScriptBridge singleton is implemented only in the Web export. It's used to access the browser's JavaScript context. This allows interaction with embedding pages or calling third-party JavaScript APIs.

Note: This singleton can be disabled at build-time to improve security. By default, the JavaScriptBridge singleton is enabled. Official export templates also have the JavaScriptBridge singleton enabled. See Compiling for the Web in the documentation for more information.

See Also

Methods

create_callback(Callable)

Creates a reference to a Callable that can be used as a callback by JavaScript. The reference must be kept until the callback happens, or it won't be called at all. See JavaScriptObject for usage.

Note: The callback function must take exactly one Array argument, which is going to be the JavaScript arguments object converted to an array.

JavaScriptObject create_callback(Callable callable)

Parameters

callable Callable

create_object(String, ...)

Qualifiers: vararg

Creates a new JavaScript object using the new constructor. The object must a valid property of the JavaScript window. See JavaScriptObject for usage.

Variant create_object(String object, ...)

Parameters

object String

download_buffer(PackedByteArray, String, String)

Prompts the user to download a file containing the specified buffer. The file will have the given name and mime type.

Note: The browser may override the MIME type provided based on the file name's extension.

Note: Browsers might block the download if JavaScriptBridge.download_buffer is not being called from a user interaction (e.g. button click).

Note: Browsers might ask the user for permission or block the download if multiple download requests are made in a quick succession.

void download_buffer(PackedByteArray buffer, String name, String mime)

Parameters

buffer PackedByteArray
name String
mime String

eval(String, bool)

Execute the string code as JavaScript code within the browser window. This is a call to the actual global JavaScript function eval().

If use_global_execution_context is true, the code will be evaluated in the global execution context. Otherwise, it is evaluated in the execution context of a function within the engine's runtime environment.

Variant eval(String code, bool use_global_execution_context)

Parameters

code String
use_global_execution_context bool

force_fs_sync

Force synchronization of the persistent file system (when enabled).

Note: This is only useful for modules or extensions that can't use FileAccess to write files.

void force_fs_sync

get_interface(String)

Returns an interface to a JavaScript object that can be used by scripts. The interface must be a valid property of the JavaScript window. The callback must accept a single Array argument, which will contain the JavaScript arguments. See JavaScriptObject for usage.

JavaScriptObject get_interface(String interface)

Parameters

interface String

is_js_buffer(JavaScriptObject)

Returns true if the given javascript_object is of type [code]ArrayBuffer[/code], [code]DataView[/code], or one of the many typed array objects.

bool is_js_buffer(JavaScriptObject javascript_object)

Parameters

javascript_object JavaScriptObject

js_buffer_to_packed_byte_array(JavaScriptObject)

Returns a copy of javascript_buffer's contents as a PackedByteArray. See also JavaScriptBridge.is_js_buffer.

PackedByteArray js_buffer_to_packed_byte_array(JavaScriptObject javascript_buffer)

Parameters

javascript_buffer JavaScriptObject

pwa_needs_update

Qualifiers: const

Returns true if a new version of the progressive web app is waiting to be activated.

Note: Only relevant when exported as a Progressive Web App.

bool pwa_needs_update

pwa_update

Performs the live update of the progressive web app. Forcing the new version to be installed and the page to be reloaded.

Note: Your application will be reloaded in all browser tabs.

Note: Only relevant when exported as a Progressive Web App and pwa_needs_update returns true.

int pwa_update

Events

pwa_update_available

Emitted when an update for this progressive web app has been detected but is waiting to be activated because a previous version is active. See pwa_update to force the update to take place immediately.

signal pwa_update_available