JavaScriptBridge

Inherits:Object

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

Description

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. SeeCompiling for the Web in the documentation for more information.

Tutorials

Methods

JavaScriptObject

create_callback(callable:Callable)

Variant

create_object(object:String, ...)vararg

void

download_buffer(buffer:PackedByteArray, name:String, mime:String = "application/octet-stream")

Variant

eval(code:String, use_global_execution_context:bool = false)

void

force_fs_sync()

JavaScriptObject

get_interface(interface:String)

bool

is_js_buffer(javascript_object:JavaScriptObject)

PackedByteArray

js_buffer_to_packed_byte_array(javascript_buffer:JavaScriptObject)

bool

pwa_needs_update()const

Error

pwa_update()


Signals

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. Seepwa_update() to force the update to take place immediately.


Method Descriptions

JavaScriptObjectcreate_callback(callable:Callable)🔗

Creates a reference to aCallable 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. SeeJavaScriptObject for usage.

Note: The callback function must take exactly oneArray argument, which is going to be the JavaScriptarguments object converted to an array.


Variantcreate_object(object:String, ...)vararg🔗

Creates a new JavaScript object using thenew constructor. Theobject must a valid property of the JavaScriptwindow. SeeJavaScriptObject for usage.


voiddownload_buffer(buffer:PackedByteArray, name:String, mime:String = "application/octet-stream")🔗

Prompts the user to download a file containing the specifiedbuffer. The file will have the givenname andmime type.

Note: The browser may override theMIME type provided based on the filename's extension.

Note: Browsers might block the download ifdownload_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.


Varianteval(code:String, use_global_execution_context:bool = false)🔗

Execute the stringcode as JavaScript code within the browser window. This is a call to the actual global JavaScript functioneval().

Ifuse_global_execution_context istrue, 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.


voidforce_fs_sync()🔗

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

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


JavaScriptObjectget_interface(interface:String)🔗

Returns an interface to a JavaScript object that can be used by scripts. Theinterface must be a valid property of the JavaScriptwindow. The callback must accept a singleArray argument, which will contain the JavaScriptarguments. SeeJavaScriptObject for usage.


boolis_js_buffer(javascript_object:JavaScriptObject)🔗

Returnstrue if the givenjavascript_object is of type[code]ArrayBuffer[/code],[code]DataView[/code], or one of the manytyped array objects.


PackedByteArrayjs_buffer_to_packed_byte_array(javascript_buffer:JavaScriptObject)🔗

Returns a copy ofjavascript_buffer's contents as aPackedByteArray. See alsois_js_buffer().


boolpwa_needs_update()const🔗

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

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


Errorpwa_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 bereloaded in all browser tabs.

Note: Only relevant when exported as a Progressive Web App andpwa_needs_update() returnstrue.


User-contributed notes

Please read theUser-contributed notes policy before submitting a comment.