Initialization and connection
The game runs in standalone mode inside the portal
WSG.environment reads standalone even though the game sits inside the portal, usually for one of these reasons:
- Reading it too early. Until
init()completes,WSG.environmentis alwaysstandalone. Read it afterawait WSG.init(), or usectx.environment. - The handshake took longer than 3 seconds. The SDK sends
initto the portal and waits 3 seconds; with no answer it switches to standalone. Initialize withdebug: trueto see a console warning when this happens. - The portal's query was lost. The SDK needs
wsg=1andhost=<portal origin>in the URL. If the game redirects to another page in its bundle, or strips the query withhistory.replaceState()beforeinit(), the SDK can't recognize the portal. - Nested iframes. If your engine creates a child iframe and loads the SDK inside it,
window.parentis your game page, not the portal. Load the SDK and callinit()in the bundle's rootindex.html. - Two SDK copies. Loading the script tag and another bundled copy of the SDK creates two instances; only the one you call
init()on connects. Use the script tag only.
Calls are rejected with not_initialized or ignored
Calls made before init() completes (including while init() is still running) have no effect: async functions reject with not_initialized, and loadingFinished(), gameplayStart() and track() are silently ignored. A typical consequence is a score rejected with no_gameplay because gameplayStart() was ignored. Always await WSG.init() first, and turn on debug to see warnings.
WSG is not defined
The SDK script hadn't run when your game code ran: the tag is missing, placed after your game script, marked async, or the SDK file failed to load (404). Put <script src="/sdk/v1/wsg-sdk.js"></script> before your game script, without async. When running locally, make sure a copy of the SDK sits at /sdk/v1/ (see Testing).
Embedding and loading
The console says "Refused to frame… frame-ancestors"
The games origin sends Content-Security-Policy: frame-ancestors <portal origin>, so only the portal may embed games. Embedding a game URL in your own test page or another website is blocked by the browser. To test, open the game URL directly (it runs standalone) or use your own server locally.
Mixed content: http:// resources are blocked
The portal and the games origin run on https, so every http:// resource is blocked. The most common case is a build that still points the SDK at http://localhost:4000/... (the template's default when running Vite). Your submission must use /sdk/v1/wsg-sdk.js and relative paths for every asset.
The "Loading game" overlay never goes away, or only after 30 seconds
The portal only removes the overlay when it receives loadingFinished(), or on its own after 30 seconds. Check that your game calls WSG.loadingFinished() after init() has completed, once the first screen is ready.
Assets 404 on the portal but work locally
Usually caused by absolute paths (/assets/... points at the origin root instead of your version folder), wrong letter case (the games origin is case-sensitive), or files outside the build folder. Test with the production-like layout to catch this early.
Audio and display
No audio, especially on iPhone
- Browsers only allow audio after a player action. Create or
resume()yourAudioContextright inside the first tap handler. - Check whether the game is still muted from
audio(false)orpauseand never unmuted onaudio(true)/resume. - On iPhone, flipping the silent switch also silences Web Audio.
The page scrolls, zooms or selects text on touch
Add the user-scalable=no viewport meta tag and the overflow: hidden; touch-action: none; user-select: none CSS shown in Game requirements.
The game doesn't stop when switching tabs
requestAnimationFrame stops by itself in hidden tabs, but setInterval, setTimeout and audio don't. Listen to WSG.on('pause') and WSG.on('resume') to stop everything; the SDK emits both events on the portal and in standalone mode.
Scores
Scores rejected with no_gameplay
The server didn't see gameplay running, or gameplayStop() happened more than 10 seconds earlier. Check that gameplayStart() is called after init() completes and that the score is submitted right after gameplayStop(), within 10 seconds.
Scores rejected with too_fast
The session's total gameplay time up to the submission is shorter than limits.minDurationMs. Set minDurationMs to the fastest time in which a valid run can end. With scoreOrder: "asc", too_fast also means the declared time is shorter than the time the server measured: see Time scores.
Scores rejected with rate_too_high
Score divided by seconds played (added up over the session) exceeds limits.maxScorePerSecond. Recompute the maximum scoring rate from your design and multiply by 1.5, and check that the game calls gameplayStart() as soon as scoring starts: see Play time across pauses and revives.
Scores rejected with invalid_score or over_max
invalid_score: the score has a fractional part, is negative or exceeds 2^53 — round it with Math.floor() before submitting. over_max: the score is above limits.maxScore — clamp it in-game, or raise maxScore in a later version if the design allows it.
Standalone accepts scores that the portal rejects
Standalone mode runs none of the anti-cheat rules. Always check scores on the staging portal; see Anti-cheat rules.
The submission succeeded but the leaderboard didn't change
Each player has a single row per period holding their best score, so a score below their record changes nothing (improved: false). With scoreOrder: "asc", lower scores are the better ones. The daily and weekly periods reset at 00:00 Vietnam time.
Other
WSG.storage data disappeared
Data is tied to the guest account, and the guest account is tied to a browser cookie. Clearing cookies, browsing privately or switching devices means a new player with an empty store.
share() returns ok: false
The player cancelled the share sheet, the browser has no navigator.share and refused clipboard access, or the call wasn't made right inside a tap/click handler. If text is longer than 280 characters or url isn't an absolute http/https URL, the Promise rejects with invalid_argument instead of returning ok: false (on the portal and in standalone mode alike).
getToken() returns null
Tokens only exist on the portal. In standalone and disabled modes, getToken() always returns null.
May my game call its own server?
Not by default: a bundle may only load resources from itself and the SDK file. If your game needs its own server, agree on it with the operations team first and authenticate players with the portal's token; see Game requirements and Player authentication.
