# Environments and query overrides

`SDK.environment` is a string you can read after `init()` resolves. It is `"disabled"` until then.

| Value | Meaning |
| --- | --- |
| `zokogames` | The game is inside the portal's iframe (the live site, the Preview tool or the build preview in the console). All features are real. |
| `local` | The in-page mock described in [local testing](https://docs.zokogames.com/getting-started/local-testing). |
| `disabled` | Neither of the above. Every SDK module member (methods reject, properties throw) fails with `sdkDisabled`. Only `init()`, `environment` and `isQaTool` keep working. You see it, for example, when you open your build's own address directly or frame the game on your own site. |

## How the SDK decides

1. If the page is the top-level window (not in an iframe), it is `local` when the host is `localhost`, `127.0.0.1`, `[::1]` or `*.localhost`, or when the URL has `useLocalSdk=true`. Otherwise it is `disabled`.
2. If the page is in an iframe, the SDK sends a handshake to the parent and waits up to 1.5 seconds for the portal to answer. When the parent page is the portal itself (`https` on `zokogames.com`), it waits up to 15 seconds. A valid answer gives `zokogames`. Only an answer from a ZokoGames page (`https` on `zokogames.com` or one of its subdomains, except the game hosts `g-<slug>` and the preview runner `preview-run`), a local host (only while the game itself runs on a local host) or the game's own origin counts: an answer from any other site is ignored, so a site that frames your game cannot pose as the portal. If nothing answers, the SDK falls back to `local` when local mode is allowed by the rules above, and to `disabled` otherwise.

The practical consequence: a game uploaded to a random web host does not get a mock unless you add `?useLocalSdk=true`, which is deliberate. A game that ships its own copy of itself elsewhere keeps working, it just does not talk to the portal.

```js
await SDK.init();
switch (SDK.environment) {
  case "zokogames": break;                  // production behaviour
  case "local": showDevBadge(); break;      // your machine
  case "disabled": hidePortalFeatures(); break;
}
```

## Query parameters the SDK reads

| Parameter | Where it applies | Purpose |
| --- | --- | --- |
| `useLocalSdk=true` | Any host | Allows local mode off `localhost`. |
| `sdk_debug=true` | Everywhere | Logs every call. Turn it on to diagnose a problem in the preview tool. |
| `qaTool=true` | Everywhere | Makes `SDK.isQaTool` `true`. |
| `ad_response=...` | Local mode only | Forces ad requests to fail with the given code. |
| Mock switches (`disableChat`, `muteAudio`, `user_response` and so on) | Local mode only | Listed in [local testing](https://docs.zokogames.com/getting-started/local-testing). |

In the portal these parameters are ignored for anything except logging. Players cannot change their identity or ad behaviour by editing the URL.

## Initialisation errors

`init()` itself never rejects. Failures show up as `disabled`. After that:

- Calling a method before `init()` resolved rejects (or throws, for synchronous members) with `sdkNotInitialized`.
- Calling it while disabled gives `sdkDisabled`.

See [errors](https://docs.zokogames.com/sdk/introduction#errors) for the full list.

## Next steps

- [Testing with local mode and the Preview tool](https://docs.zokogames.com/getting-started/local-testing)
- [Introduction, init and errors](https://docs.zokogames.com/sdk/introduction)
