Skip to content

Commit ef96f93

Browse files
authored
Merge pull request #10232 from Calinou/exporting-for-web-progressive-web-app
Document exporting as progressive web app in Exporting for the web
2 parents 8c29125 + 40d1613 commit ef96f93

File tree

4 files changed

+128
-22
lines changed

4 files changed

+128
-22
lines changed

tutorials/audio/audio_buses.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ Finally, toggle the **Playing** property to **On** and sound will flow.
8888
Adding effects
8989
--------------
9090

91+
.. warning::
92+
93+
This feature is not supported on the web platform if the AudioStreamPlayer's
94+
playback mode is set to **Sample**, which is the default. It will only work if the
95+
playback mode is set to **Stream**, at the cost of increased latency if threads
96+
are not enabled.
97+
98+
See :ref:`Audio playback in the Exporting for the Web documentation <doc_exporting_for_web_audio_playback>`
99+
for details.
100+
91101
Audio buses can contain all sorts of effects. These effects modify the sound in
92102
one way or another and are applied in order.
93103

tutorials/audio/audio_streams.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ Unlike for 2D, the 3D version of AudioStreamPlayer has a few more advanced optio
8080
Reverb buses
8181
~~~~~~~~~~~~
8282

83+
.. warning::
84+
85+
This feature is not supported on the web platform if the AudioStreamPlayer's
86+
playback mode is set to **Sample**, which is the default. It will only work if the
87+
playback mode is set to **Stream**, at the cost of increased latency if threads
88+
are not enabled.
89+
90+
See :ref:`Audio playback in the Exporting for the Web documentation <doc_exporting_for_web_audio_playback>`
91+
for details.
92+
8393
Godot allows for 3D audio streams that enter a specific Area3D node to send dry
8494
and wet audio to separate buses. This is useful when you have several reverb
8595
configurations for different types of rooms. This is done by enabling this type
@@ -102,6 +112,16 @@ that effect.
102112
Doppler
103113
~~~~~~~
104114

115+
.. warning::
116+
117+
This feature is not supported on the web platform if the AudioStreamPlayer's
118+
playback mode is set to **Sample**, which is the default. It will only work if the
119+
playback mode is set to **Stream**, at the cost of increased latency if threads
120+
are not enabled.
121+
122+
See :ref:`Audio playback in the Exporting for the Web documentation <doc_exporting_for_web_audio_playback>`
123+
for details.
124+
105125
When the relative velocity between an emitter and listener changes, this is
106126
perceived as an increase or decrease in the pitch of the emitted sound.
107127
Godot can track velocity changes in the AudioStreamPlayer3D and Camera nodes.

tutorials/editor/using_the_web_editor.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ of the Web platform:
6969
.. seealso::
7070

7171
See the
72-
`list of open issues on GitHub related to the web editor <https://github.com/godotengine/godot/issues?q=is%3Aopen+is%3Aissue+label%3Aplatform%3Ahtml5+label%3Atopic%3Aeditor>`__ for a list of known bugs.
72+
`list of open issues on GitHub related to the web editor <https://github.com/godotengine/godot/issues?q=is%3Aopen+is%3Aissue+label%3Aplatform%3Aweb+label%3Atopic%3Aeditor>`__
73+
for a list of known bugs.
7374

7475
Importing a project
7576
-------------------

tutorials/export/exporting_for_web.rst

Lines changed: 96 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ Exporting for the Web
1111

1212
HTML5 export allows publishing games made in Godot Engine to the browser.
1313
This requires support for `WebAssembly
14-
<https://webassembly.org/>`__, `WebGL <https://www.khronos.org/webgl/>`__ and
15-
`SharedArrayBuffer <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer>`_
14+
<https://webassembly.org/>`__ and `WebGL 2.0 <https://www.khronos.org/webgl/>`__
1615
in the user's browser.
1716

1817
.. attention::
@@ -26,21 +25,16 @@ in the user's browser.
2625
with :kbd:`F12` (:kbd:`Cmd + Option + I` on macOS), to view
2726
**debug information** like JavaScript, engine, and WebGL errors.
2827

29-
.. attention::
30-
31-
Godot 4's HTML5 exports currently cannot run on macOS and iOS due to upstream bugs
32-
with SharedArrayBuffer and WebGL 2.0. We recommend using
33-
:ref:`macOS <doc_exporting_for_macos>` and :ref:`iOS <doc_exporting_for_ios>`
34-
native export functionality instead, as it will also result in better performance.
28+
.. seealso::
3529

36-
Godot 3's HTML5 exports are more compatible with various browsers in
37-
general, especially when using the GLES2 rendering backend (which only
38-
requires WebGL 1.0).
30+
See the
31+
`list of open issues on GitHub related to the web export <https://github.com/godotengine/godot/issues?q=is%3Aopen+is%3Aissue+label%3Aplatform%3Aweb>`__
32+
for a list of known bugs.
3933

4034
Export file name
4135
----------------
4236

43-
We do suggest users to export their Web projects with ``index.html`` as the file name.
37+
We suggest users to export their Web projects with ``index.html`` as the file name.
4438
``index.html`` is usually the default file loaded by web servers when accessing the
4539
parent directory, usually hiding the name of that file.
4640

@@ -54,13 +48,38 @@ WebGL version
5448
-------------
5549

5650
Godot 4.0 and later can only target WebGL 2.0 (using the Compatibility rendering
57-
method). There is no stable way to run Vulkan applications on the web yet.
51+
method). Forward+/Mobile are not supported on the web platform, as these
52+
rendering methods are designed around modern low-level graphics APIs. Godot
53+
currently does not support WebGPU, which is a prerequisite for allowing
54+
Forward+/Mobile to run on the web platform.
5855

5956
See `Can I use WebGL 2.0 <https://caniuse.com/webgl2>`__ for a list of browser
6057
versions supporting WebGL 2.0. Note that Safari has several issues with WebGL
6158
2.0 support that other browsers don't have, so we recommend using a
6259
Chromium-based browser or Firefox if possible.
6360

61+
.. _doc_exporting_for_web_audio_playback:
62+
63+
Audio playback
64+
--------------
65+
66+
Since Godot 4.3, audio playback is done using the Web Audio API on the web
67+
platform. This **Sample** playback mode allows for low latency even when the
68+
project is exported without thread support, but it has several limitations:
69+
70+
- AudioEffects are not supported.
71+
- :ref:`Reverberation and doppler <doc_audio_streams_reverb_buses>` effects are not supported.
72+
- Procedural audio generation is not supported.
73+
- Positional audio may not always work correctly depending on the node's properties.
74+
75+
To use Godot's own audio playback system on the web platform, you can change the
76+
default playback mode using the **Audio > General > Default Playback Type.web**
77+
project setting, or change the **Playback Type** property to **Stream** on an
78+
:ref:`class_AudioStreamPlayer`, :ref:`class_AudioStreamPlayer2D` or
79+
:ref:`class_AudioStreamPlayer3D` node. This leads to increased latency
80+
(especially when thread support is disabled), but it allows the full suite
81+
of Godot's audio features to work.
82+
6483
.. _doc_javascript_export_options:
6584

6685
Export options
@@ -73,7 +92,7 @@ game in the default browser for testing.
7392
If your project uses GDExtension **Extension Support** needs to be enabled.
7493

7594
If you plan to use :ref:`VRAM compression <doc_importing_images>` make sure that
76-
**Vram Texture Compression** is enabled for the targeted platforms (enabling
95+
**VRAM Texture Compression** is enabled for the targeted platforms (enabling
7796
both **For Desktop** and **For Mobile** will result in a bigger, but more
7897
compatible export).
7998

@@ -91,6 +110,59 @@ JavaScript APIs, include CSS, or run JavaScript code.
91110
To customize the generated file, use the **Custom HTML shell**
92111
option.
93112

113+
.. _doc_exporting_for_web_thread_extension_support:
114+
115+
Thread and extension support
116+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
117+
118+
If **Thread Support** is enabled, the exported project will be able to
119+
:ref:`make use of multithreading <doc_using_multiple_threads>` to improve
120+
performance. This also allows for low-latency audio playback
121+
when the playback type is set to **Stream** (instead of the default **Sample**
122+
that is used in web exports). Enabling this feature requires the use of
123+
cross-origin isolation headers, which are described in the
124+
:ref:`doc_exporting_for_web_serving_the_files` section below.
125+
126+
If **Extensions Support** is enabled, :ref:`GDExtensions <doc_what_is_gdextension>`
127+
will be able to be loaded. Note that GDExtensions still need to be specifically
128+
compiled for the web platform to work. Like thread support, enabling this feature
129+
requires the use of cross-origin isolation headers.
130+
131+
Exporting as a Progressive Web App (PWA)
132+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
133+
134+
If **Progressive Web App > Enable** is enabled, it will have several effects:
135+
136+
- Configure high-resolution icons, a display mode and screen orientation. These
137+
are configured at the end of the Progressive Web App section in the export
138+
options. These options are used if the user adds the project to their device's
139+
homescreen, which is common on mobile platforms. This is also supported on
140+
desktop platforms, albeit in a more limited capacity.
141+
142+
- Allow the project to be loaded without an Internet connection if it has been
143+
loaded at least once beforehand. This works thanks to the *service worker*
144+
that is installed when the project is first loaded in the user's browser. This
145+
service worker provides a local fallback when no Internet connection is
146+
available.
147+
148+
- Note that web browsers can choose to evict the cached data if the user runs
149+
low on disk space, or if the user hasn't opened the project for a while.
150+
To ensure data is cached for a longer duration, the user can bookmark the page,
151+
or ideally add it to their device's home screen.
152+
153+
- If the offline data is not available because it was evicted from the cache,
154+
you can configure an **Offline Page** that will be displayed in this case.
155+
The page must be in HTML format and will be saved on the client's machine
156+
the first time the project is loaded.
157+
158+
- Ensure cross-origin isolation headers are always present, even if the web
159+
server hasn't been configured to send them. This allows exports with threads
160+
enabled to work when hosted on any website, even if there is no way for you to
161+
control the headers it sends.
162+
163+
- This behavior can be disabled by unchecking **Enable Cross Origin Isolation Headers**
164+
in the Progressive Web App section.
165+
94166
Limitations
95167
-----------
96168

@@ -218,8 +290,8 @@ used, see :ref:`doc_customizing_html5_shell`.
218290

219291
.. warning::
220292

221-
To ensure low audio latency and the ability to use :ref:`class_Thread` in web exports,
222-
Godot 4 web exports always use
293+
If either :ref:`thread support or extension support <doc_exporting_for_web_thread_extension_support>`
294+
are enabled, the exported project will require
223295
`SharedArrayBuffer <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer>`__.
224296
This requires a :ref:`secure context <doc_javascript_secure_contexts>`,
225297
while also requiring the following CORS headers to be set when serving the files:
@@ -230,11 +302,13 @@ used, see :ref:`doc_customizing_html5_shell`.
230302
Cross-Origin-Embedder-Policy: require-corp
231303

232304
If you don't control the web server or are unable to add response headers,
233-
use `coi-serviceworker <https://github.com/gzuidhof/coi-serviceworker>`__
234-
as a workaround.
305+
check **Progressive Web App > Enable** in the export options. This applies
306+
a service worker-based workaround that allows the project to run by
307+
simulating the presence of these response headers. A secure context
308+
is still required in this case.
235309

236-
If the client doesn't receive the required response headers,
237-
**the project will not run**.
310+
If the client doesn't receive the required response headers or the service
311+
worker-based workaround is not applied, **the project will not run**.
238312

239313
The generated ``.html`` file can be used as ``DirectoryIndex`` in Apache
240314
servers and can be renamed to e.g. ``index.html`` at any time. Its name is
@@ -302,7 +376,8 @@ supported on your web server for further file size savings.
302376
Interacting with the browser and JavaScript
303377
-------------------------------------------
304378

305-
See the :ref:`dedicated page <doc_web_javascript_bridge>` on how to interact with JavaScript and access some unique Web browser features.
379+
See the :ref:`dedicated page <doc_web_javascript_bridge>` on how to interact
380+
with JavaScript and access some unique Web browser features.
306381

307382
Environment variables
308383
---------------------

0 commit comments

Comments
 (0)