JavaScript.xml 4.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="JavaScript" inherits="Object" version="4.0">
  3. <brief_description>
  4. Singleton that connects the engine with the browser's JavaScript context in HTML5 export.
  5. </brief_description>
  6. <description>
  7. The JavaScript singleton is implemented only in the HTML5 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 JavaScript singleton is enabled. Official export templates also have the JavaScript singleton enabled. See [url=$DOCS_URL/development/compiling/compiling_for_web.html]Compiling for the Web[/url] in the documentation for more information.
  9. </description>
  10. <tutorials>
  11. <link title="Exporting for the Web: Calling JavaScript from script">$DOCS_URL/tutorials/export/exporting_for_web.html#calling-javascript-from-script</link>
  12. </tutorials>
  13. <methods>
  14. <method name="create_callback">
  15. <return type="JavaScriptObject" />
  16. <argument 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. </description>
  20. </method>
  21. <method name="create_object" qualifiers="vararg">
  22. <return type="Variant" />
  23. <argument index="0" name="object" type="String" />
  24. <description>
  25. Creates a new JavaScript object using the [code]new[/code] constructor. The [code]object[/code] must a valid property of the JavaScript [code]window[/code]. See [JavaScriptObject] for usage.
  26. </description>
  27. </method>
  28. <method name="download_buffer">
  29. <return type="void" />
  30. <argument index="0" name="buffer" type="PackedByteArray" />
  31. <argument index="1" name="name" type="String" />
  32. <argument index="2" name="mime" type="String" default="&quot;application/octet-stream&quot;" />
  33. <description>
  34. Prompts the user to download a file containing the specified [code]buffer[/code]. The file will have the given [code]name[/code] and [code]mime[/code] type.
  35. [b]Note:[/b] The browser may override the [url=https://en.wikipedia.org/wiki/Media_type]MIME type[/url] provided based on the file [code]name[/code]'s extension.
  36. [b]Note:[/b] Browsers might block the download if [method download_buffer] is not being called from a user interaction (e.g. button click).
  37. [b]Note:[/b] Browsers might ask the user for permission or block the download if multiple download requests are made in a quick succession.
  38. </description>
  39. </method>
  40. <method name="eval">
  41. <return type="Variant" />
  42. <argument index="0" name="code" type="String" />
  43. <argument index="1" name="use_global_execution_context" type="bool" default="false" />
  44. <description>
  45. Execute the string [code]code[/code] as JavaScript code within the browser window. This is a call to the actual global JavaScript function [code]eval()[/code].
  46. If [code]use_global_execution_context[/code] 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.
  47. </description>
  48. </method>
  49. <method name="get_interface">
  50. <return type="JavaScriptObject" />
  51. <argument index="0" name="interface" type="String" />
  52. <description>
  53. Returns an interface to a JavaScript object that can be used by scripts. The [code]interface[/code] 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.
  54. </description>
  55. </method>
  56. <method name="pwa_needs_update" qualifiers="const">
  57. <return type="bool" />
  58. <description>
  59. Returns [code]true[/code] if a new version of the progressive web app is waiting to be activated.
  60. [b]Note:[/b] Only relevant when exported as a Progressive Web App.
  61. </description>
  62. </method>
  63. <method name="pwa_update">
  64. <return type="int" enum="Error" />
  65. <description>
  66. Performs the live update of the progressive web app. Forcing the new version to be installed and the page to be reloaded.
  67. [b]Note:[/b] Your application will be [b]reloaded in all browser tabs[/b].
  68. [b]Note:[/b] Only relevant when exported as a Progressive Web App and [method pwa_needs_update] returns [code]true[/code].
  69. </description>
  70. </method>
  71. </methods>
  72. <signals>
  73. <signal name="pwa_update_available">
  74. <description>
  75. 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.
  76. </description>
  77. </signal>
  78. </signals>
  79. </class>