Table of Contents

Class JavaScriptBridgeInstance

Namespace
Godot
Assembly
GodotSharp.dll

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.

[GodotClassName("JavaScriptBridge")]
public class JavaScriptBridgeInstance : GodotObject, IDisposable
Inheritance
JavaScriptBridgeInstance
Implements
Inherited Members

Methods

CreateCallback(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.

public JavaScriptObject CreateCallback(Callable callable)

Parameters

callable Callable

Returns

JavaScriptObject

CreateObject(string, params Variant[])

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

public Variant CreateObject(string @object, params Variant[] args)

Parameters

object string
args Variant[]

Returns

Variant

DownloadBuffer(byte[], 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 DownloadBuffer(byte[], string, string) 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.

public void DownloadBuffer(byte[] buffer, string name, string mime = "application/octet-stream")

Parameters

buffer byte[]
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 useGlobalExecutionContext 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.

public Variant Eval(string code, bool useGlobalExecutionContext = false)

Parameters

code string
useGlobalExecutionContext bool

Returns

Variant

ForceFsSync()

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.

public void ForceFsSync()

GetInterface(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.

public JavaScriptObject GetInterface(string @interface)

Parameters

interface string

Returns

JavaScriptObject

HasGodotClassMethod(in godot_string_name)

Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.

protected override bool HasGodotClassMethod(in godot_string_name method)

Parameters

method godot_string_name

Name of the method to check for.

Returns

bool

HasGodotClassSignal(in godot_string_name)

Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.

protected override bool HasGodotClassSignal(in godot_string_name signal)

Parameters

signal godot_string_name

Name of the signal to check for.

Returns

bool

InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)

Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.

protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)

Parameters

method godot_string_name

Name of the method to invoke.

args NativeVariantPtrArgs

Arguments to use with the invoked method.

ret godot_variant

Value returned by the invoked method.

Returns

bool

PwaNeedsUpdate()

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.

public bool PwaNeedsUpdate()

Returns

bool

PwaUpdate()

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 PwaNeedsUpdate() returns true.

public Error PwaUpdate()

Returns

Error

Events

PwaUpdateAvailable

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

public event Action PwaUpdateAvailable

Event Type

Action