nisovin / godot-coi-serviceworker

A Godot plugin that enables cross-origin isolation for web exports
https://godotengine.org/asset-library/asset/1818
MIT License
40 stars 3 forks source link
godot godot4

Godot COI Service Worker

This plugin makes use of the coi-serviceworker Javascript library to enable cross-origin isolation in Godot 4 games for situations in which you can't control the headers. In other words, it fixes the SharedArrayBuffer error.

See also this Godot proposal.

Read This First: Alternatives

  1. If your web host allows you to set the proper headers, you should do that instead. For example, itch.io and Newgrounds both have options to enable this feature (refered to as enabling SharedArrayBuffer support).
  2. In Godot 4.3, you can export a build that doesn't use threads. This should allow you to run your game without the cross-origin headers, which means you would not need this plugin. This may be a better alternative in many situations. More info here
  3. Also in Godot 4.3, you can export a Progressive Web App (PWA), which has the option to have the functionality of this plugin built-in. More info here

Usage

Simply install this plugin and enable it in your project settings. When you export a Web build, the plugin will add the Javascript file to enable this feature. This script will reload the page on the user's first load to magically add the required COOP and COEP headers in a service worker. See the coi-serviceworker project page for more information.

Export Options

Limitations

There is a good chance that any host that embeds your game in an iframe within another page will still not work with this addon. If you were to open that embedded page into its own tab, it will probably work, but while it is embedded it won't. You can use the export option mentioned above to break out of the iframe.

Version History

v1.2

v1.1

v1.0