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 ¶
- func Advanced() class
- func CreateCallback(callable func(args []any) any) JavaScriptObject.Instance
- func CreateObject(obj string, args ...any) any
- func DownloadBuffer(buffer []byte, name string)
- func DownloadBufferOptions(buffer []byte, name string, mime string)
- func Eval(code string, use_global_execution_context bool) any
- func EvalOptions(code string, use_global_execution_context bool) any
- func ForceFsSync()
- func GetInterface(intf string) JavaScriptObject.Instance
- func IsJsBuffer(javascript_object JavaScriptObject.Instance) bool
- func JsBufferToPackedByteArray(javascript_buffer JavaScriptObject.Instance) []byte
- func OnPwaUpdateAvailable(cb func(), flags ...Signal.Flags)
- func PwaNeedsUpdate() bool
- func PwaUpdate() error
- type Extension
- type ID
- type Instance
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 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 ¶
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
type 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.
type Instance ¶
type Instance [1]gdclass.JavaScriptBridge
Instance of the class with convieniently typed arguments and results.