HTML5 v2 SDK
HTML5 v2 SDK is the current stable version of the HTML5 SDK but will be soon deprecated in favor of HTML5 v3 SDK.
You can install the SDK by including the following script in the head of your game's
The SDK doesn't need to be initialized before being used. The initialization is done internally.
Your game runs on different domains during development/release, which the SDK considers to be different environments.
127.0.0.1domains are considered
localenvironments. Advertisements are not available. Instead, an overlay text will be displayed. For other events such as happy time, gameplay start, etc. the console output can be consulted. If you are using a different domain/ip for local development, you can always enforce the
localenvironment by appending the
?useLocalSdk=truequery parameter to the URL in your browser.
CrazyGamesdomains the SDK has the
crazygamesenvironment, where it functions properly.
- On any other domains (including your domain on which you may host your game) the SDK has the
disabledenvironment. All the calls to the SDK methods will throw an error (or call the error callback). To prevent this, we recommend checking on which environment the SDK is running, and avoid making use of it outside
You can check the environment like this:
You can check if the game is running in QA Tool like this:
To simulate the setup used on CrazyGames, download this template. The file
sdk.html uses our game loader to display your game. It assumes that
index.html contains the html of your game. This lets your game run using the same setup as it would on crazygames.com. You'll just have to browse to
localhost:port/sdk.html to see our game loader in action.
When you upload your game we only look at your
index.html file, and provide the game loader for you. The
sdk.html page will not be used: keep any logic out of that file, and make sure that your
index.html does not include the game loader.
The SDK has the following modules:
ad- display video ads, detect adblockers
banner- display banners
game- various game events
user- for interacting with the currently signed in user
Each one of these modules can be accessed as follows:
window.CrazyGames.SDK.[moduleName], for example
Disable unwanted page scroll
By default, browsers scroll the page when a user presses spacebar or the arrow keys. Your game should prevent this behavior. You might not notice it in development because your game is taking on the full height of the window. But when your game is embedded on CrazyGames, you’ll need to prevent scroll. You can do so by adding the following code to your game:
Migration from HTML5 v1 SDK
You can find the docs for the old HTML5 v1 SDK here.
You don't need to call
init() anymore. The new SDK does the initialization on its own.
Global event listeners
The global events (
'adFinished', etc.) are gone. Now the methods accept a callback object with various callbacks. Although callbacks can be passed to almost every SDK method in the SDK V2, they are most useful for ads, where you need to know when an ad starts or completes.
const crazysdk = window.CrazyGames.CrazySDK.getInstance();
// init and wait until it gets initialized...
crazysdk.removeEventListener("adFinished", () => console.log("End rewarded ad (callback)"));
crazysdk.removeEventListener("adError", (error) => console.log("Error rewarded ad (callback)", error));
crazysdk.removeEventListener("adStarted", () => console.log("Start rewarded ad (callback)"));
Single banner request
requestBanner method can request a single banner at a time. The limit of maximum 2 banners of the same size is still present.