Management API Reference

Unity WebGL

To make these instructions concrete, we have created a sample cross-app wallet called Rapidfire ID. To interact with it, you can find its SDK in the NPM package directory: @rapidfire/id.

You can check out the GitHub repository for Rapidfire Wallet to learn how to create your own wallet.

This guide will walk you through adding support for any cross-app wallet into a Unity app by integrating the Mobile Wallet Protocol.

When doing Build And Run from your Unity Build Settings with the target platform WebGL you will notice that no popups are allowed. This is due to the Cross-Origin-Opener-Policy header being set to same-origin-allow-popups by default. This is a security feature to prevent popups from different origins.

Setup#

Follow the setup guide.

Running instructions#

There are two main things to consider when running your Unity WebGL build with cross-app wallet support:

  1. For any cross-app wallet to work, you need to host the build or run it locally with Cross-Origin-Opener-Policy set to same-origin-allow-popups.
  2. Compression Format: Set to Disabled (Player Settings > Publishing Settings) for final builds.

Here's an example setup for testing your cross-app wallet locally using express server. Please note that in this example, the build output is in the build-output directory. Once your build is done, follow these steps:

1. Create a Project Folder and Setup Files#

Create a new folder for your server project and navigate to it:


_10
mkdir unity-webgl-server
_10
cd unity-webgl-server

Create a new subfolder called build-output where you'll place your Unity WebGL build files:


_10
mkdir build-output

Copy all the files from your Unity WebGL build into the build-output folder. This should include files like:

  • index.html
  • .unityweb files
  • Other assets and build files

2. Initialize Your Node.js Project#

Initialize a new Node.js project and install Express:


_10
npm init -y
_10
npm install express

Create a new file called server.js in the root folder with the following content:

server.js
package.json

_18
const express = require("express");
_18
const path = require("path");
_18
_18
const app = express();
_18
const port = 8000;
_18
_18
app.use((req, res, next) => {
_18
res.header(
_18
"Cross-Origin-Opener-Policy",
_18
"same-origin-allow-popups",
_18
);
_18
next();
_18
});
_18
_18
app.use(express.static(path.join(__dirname, "build-output")));
_18
app.listen(port, () =>
_18
console.log(`Server running on http://localhost:${port}`),
_18
);

3. Run Your Local Server#

Start your Express server by running:


_10
node server.js

You should see the message: Server running on http://localhost:8000

Open your browser and navigate to http://localhost:8000 to see your Unity WebGL build running with cross-app wallet support enabled.

Troubleshooting#

If you encounter any issues:

  1. Make sure your build-output folder contains all the necessary Unity WebGL build files
  2. Confirm that your server is properly setting the Cross-Origin-Opener-Policy header
  3. Check browser console for any errors
  4. Ensure your cross-app wallet is properly configured to work with the Mobile Wallet Protocol

Production Deployment#

For production deployments, you'll need to configure your web server to set the Cross-Origin-Opener-Policy: same-origin-allow-popups header. The implementation depends on your hosting provider.