JavaScriptBridge

package
v0.0.0-...-ff35923 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2025 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Advanced

func Advanced() class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

func CreateCallback

func CreateCallback(callable func(args []any) any) JavaScriptObject.Instance

Creates a reference to a func 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 graphics.gd/classdb/JavaScriptObject for usage.

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

func CreateObject

func CreateObject(obj string, args ...any) any

Creates a new JavaScript object using the new constructor. The 'object' must a valid property of the JavaScript window. See graphics.gd/classdb/JavaScriptObject for usage.

func DownloadBuffer

func DownloadBuffer(buffer []byte, name 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 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.

func DownloadBufferOptions

func DownloadBufferOptions(buffer []byte, name string, mime 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 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.

func Eval

func Eval(code string, use_global_execution_context bool) any

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.

func EvalOptions

func EvalOptions(code string, use_global_execution_context bool) any

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.

func ForceFsSync

func ForceFsSync()

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

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

func GetInterface

func GetInterface(intf string) JavaScriptObject.Instance

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 slice argument, which will contain the JavaScript arguments. See graphics.gd/classdb/JavaScriptObject for usage.

func IsJsBuffer

func IsJsBuffer(javascript_object JavaScriptObject.Instance) bool

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

func JsBufferToPackedByteArray

func JsBufferToPackedByteArray(javascript_buffer JavaScriptObject.Instance) []byte

Returns a copy of 'javascript_buffer”s contents as a []byte. See also IsJsBuffer.

func OnPwaUpdateAvailable

func OnPwaUpdateAvailable(cb func(), flags ...Signal.Flags)

func PwaNeedsUpdate

func PwaNeedsUpdate() bool

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.

func PwaUpdate

func PwaUpdate() error

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.

Types

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.JavaScriptBridge

Instance of the class with convieniently typed arguments and results.

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) ID

func (self Instance) ID() ID

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL