JavaScriptBridge
Singleton that connects the engine with the browser’s JavaScript context in Web export.
JavaScriptBridge.swift:19class JavaScriptBridge
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.
This object emits the following signals:
Superclasses
class Object
Base class for all other classes in the engine.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Type members
static func createCallback(callable: Callable
) -> JavaScriptObject? 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. SeeJavaScriptObject
for usage.static func createObject(String, Variant...
) -> Variant Creates a new JavaScript object using the
new
constructor. Theobject
must a valid property of the JavaScriptwindow
. SeeJavaScriptObject
for usage.static func downloadBuffer(PackedByteArray, name: String, mime: String
) Prompts the user to download a file containing the specified
buffer
. The file will have the givenname
andmime
type.static func eval(code: String, useGlobalExecutionContext: Bool
) -> Variant Execute the string
code
as JavaScript code within the browser window. This is a call to the actual global JavaScript function [code skip-lint]eval()`.static func forceFsSync(
) Force synchronization of the persistent file system (when enabled).
static func getInterface(String
) -> JavaScriptObject? Returns an interface to a JavaScript object that can be used by scripts. The
interface
must be a valid property of the JavaScriptwindow
. The callback must accept a singleGArray
argument, which will contain the JavaScriptarguments
. SeeJavaScriptObject
for usage.static func pwaNeedsUpdate(
) -> Bool Returns
true
if a new version of the progressive web app is waiting to be activated.static func pwaUpdate(
) -> GodotError Performs the live update of the progressive web app. Forcing the new version to be installed and the page to be reloaded.
class var godotClassName: StringName
Instance members
var pwaUpdateAvailable: SimpleSignal
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.