0.2.0-dev Download ZIP
101 lines ·6.3 KB Raw
| 1 | <?xml version="1.0" encoding="UTF-8" ?> |
| 2 | <class name="JavaScriptBridge" inherits="Object" api_type="core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> |
| 3 | <brief_description> |
| 4 | Singleton that connects the engine with the browser's JavaScript context in Web export. |
| 5 | </brief_description> |
| 6 | <description> |
| 7 | 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. |
| 8 | [b]Note:[/b] 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 [url=$DOCS_URL/engine_details/development/compiling/compiling_for_web.html]Compiling for the Web[/url] in the documentation for more information. |
| 9 | </description> |
| 10 | <tutorials> |
| 11 | <link title="The JavaScriptBridge singleton">$DOCS_URL/tutorials/platform/web/javascript_bridge.html</link> |
| 12 | </tutorials> |
| 13 | <methods> |
| 14 | <method name="create_callback"> |
| 15 | <return type="JavaScriptObject" /> |
| 16 | <param index="0" name="callable" type="Callable" /> |
| 17 | <description> |
| 18 | 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. |
| 19 | [b]Note:[/b] The callback function must take exactly one [Array] argument, which is going to be the JavaScript [url=https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments]arguments object[/url] converted to an array. |
| 20 | </description> |
| 21 | </method> |
| 22 | <method name="create_object" qualifiers="vararg"> |
| 23 | <return type="Variant" /> |
| 24 | <param index="0" name="object" type="String" /> |
| 25 | <description> |
| 26 | Creates a new JavaScript object using the [code]new[/code] constructor. The [param object] must a valid property of the JavaScript [code]window[/code]. See [JavaScriptObject] for usage. |
| 27 | </description> |
| 28 | </method> |
| 29 | <method name="download_buffer"> |
| 30 | <return type="void" /> |
| 31 | <param index="0" name="buffer" type="PackedByteArray" /> |
| 32 | <param index="1" name="name" type="String" /> |
| 33 | <param index="2" name="mime" type="String" default=""application/octet-stream"" /> |
| 34 | <description> |
| 35 | Prompts the user to download a file containing the specified [param buffer]. The file will have the given [param name] and [param mime] type. |
| 36 | [b]Note:[/b] The browser may override the [url=https://en.wikipedia.org/wiki/Media_type]MIME type[/url] provided based on the file [param name]'s extension. |
| 37 | [b]Note:[/b] Browsers might block the download if [method download_buffer] is not being called from a user interaction (e.g. button click). |
| 38 | [b]Note:[/b] Browsers might ask the user for permission or block the download if multiple download requests are made in a quick succession. |
| 39 | </description> |
| 40 | </method> |
| 41 | <method name="eval"> |
| 42 | <return type="Variant" /> |
| 43 | <param index="0" name="code" type="String" /> |
| 44 | <param index="1" name="use_global_execution_context" type="bool" default="false" /> |
| 45 | <description> |
| 46 | Execute the string [param code] as JavaScript code within the browser window. This is a call to the actual global JavaScript function [code skip-lint]eval()[/code]. |
| 47 | If [param use_global_execution_context] is [code]true[/code], 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. |
| 48 | </description> |
| 49 | </method> |
| 50 | <method name="force_fs_sync"> |
| 51 | <return type="void" /> |
| 52 | <description> |
| 53 | Force synchronization of the persistent file system (when enabled). |
| 54 | [b]Note:[/b] This is only useful for modules or extensions that can't use [FileAccess] to write files. |
| 55 | </description> |
| 56 | </method> |
| 57 | <method name="get_interface"> |
| 58 | <return type="JavaScriptObject" /> |
| 59 | <param index="0" name="interface" type="String" /> |
| 60 | <description> |
| 61 | Returns an interface to a JavaScript object that can be used by scripts. The [param interface] must be a valid property of the JavaScript [code]window[/code]. The callback must accept a single [Array] argument, which will contain the JavaScript [code]arguments[/code]. See [JavaScriptObject] for usage. |
| 62 | </description> |
| 63 | </method> |
| 64 | <method name="is_js_buffer"> |
| 65 | <return type="bool" /> |
| 66 | <param index="0" name="javascript_object" type="JavaScriptObject" /> |
| 67 | <description> |
| 68 | Returns [code]true[/code] if the given [param javascript_object] is of type [url=https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer]ArrayBuffer[/url], [url=https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView]DataView[/url], or one of the many [url=https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray]typed array objects[/url]. |
| 69 | </description> |
| 70 | </method> |
| 71 | <method name="js_buffer_to_packed_byte_array"> |
| 72 | <return type="PackedByteArray" /> |
| 73 | <param index="0" name="javascript_buffer" type="JavaScriptObject" /> |
| 74 | <description> |
| 75 | Returns a copy of [param javascript_buffer]'s contents as a [PackedByteArray]. See also [method is_js_buffer]. |
| 76 | </description> |
| 77 | </method> |
| 78 | <method name="pwa_needs_update" qualifiers="const"> |
| 79 | <return type="bool" /> |
| 80 | <description> |
| 81 | Returns [code]true[/code] if a new version of the progressive web app is waiting to be activated. |
| 82 | [b]Note:[/b] Only relevant when exported as a Progressive Web App. |
| 83 | </description> |
| 84 | </method> |
| 85 | <method name="pwa_update"> |
| 86 | <return type="int" enum="Error" /> |
| 87 | <description> |
| 88 | Performs the live update of the progressive web app. Forcing the new version to be installed and the page to be reloaded. |
| 89 | [b]Note:[/b] Your application will be [b]reloaded in all browser tabs[/b]. |
| 90 | [b]Note:[/b] Only relevant when exported as a Progressive Web App and [method pwa_needs_update] returns [code]true[/code]. |
| 91 | </description> |
| 92 | </method> |
| 93 | </methods> |
| 94 | <signals> |
| 95 | <signal name="pwa_update_available"> |
| 96 | <description> |
| 97 | 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 [method pwa_update] to force the update to take place immediately. |
| 98 | </description> |
| 99 | </signal> |
| 100 | </signals> |
| 101 | </class> |