HTML5 Resources
This page contains other resources relevant for many HTML5 games.
Sitelock
Protecting HTML5 games
To prevent your game from being stolen by other websites, you should consider checking if the game is running on CrazyGames or not.
An HTML5 game will be loaded from a URL that looks like this https://cubes-2048-io.game-files.crazygames.com/cubes-2048-io/13/index.html
. Your sitelock should check if the origin of the URL the game is currently running on ends with crazygames.com
. Sample code:
If not, you can, among other things, show a message "Available only on CrazyGames" or just a blank screen.
To improve the security of your sitelock, you can consider using an obfuscator (e.g.: https://obfuscator.io/) to obfuscate (part of) your game.
Protecting Iframe games
One way to prevent iframe embedding is by using the CSP header Content-Security-Policy: frame-ancestors [...]
. If you submit your game as an iframe game, you may have already done this to protect it from other websites embedding it. You should be aware however that CrazyGames has a lot of regional domains, for example, www.crazygames.no, www.1001juegos.com, www.crazygames.fr.
This is the full list of domains that you will have to whitelist:
// General
*.crazygames.com
crazygames.* // * can be a TLD consisting of 1 or 2 parts like .fr or .com.br
// Exhaustive list
www.crazygames.com
de.crazygames.com
it.crazygames.com
vn.crazygames.com
gr.crazygames.com
ar.crazygames.com
th.crazygames.com
www.crazygames.fr
www.crazygames.co.id
www.crazygames.cz
www.crazygames.dk
www.crazygames.hu
www.crazygames.nl
www.crazygames.no
www.crazygames.pl
www.crazygames.com.br
www.crazygames.ro
www.crazygames.fi
www.crazygames.se
www.crazygames.ru
www.crazygames.com.ua
www.crazygames.at
www.crazygames.jp
www.crazygames.pt
www.crazygames.vn
www.crazygames.com.vn
www.crazygames.co.kr
// video ads run on
games.crazygames.com
//deprecated domains (no longer need whitelisting)
www.1001juegos.com
tr.crazygames.com
Common fixes
The snippet below fixes a number of UX issues caused by default browser behavior
- Unwanted page scroll
- Unwanted key events
- Visibility changes on Samsung App
- Appearance of context menu outside unity canvas
// Disable unwanted page scroll.
window.addEventListener("wheel", (event) => event.preventDefault(), {
passive: false,
});
// Disable unwanted key events and spacebar scrolling.
window.addEventListener("keydown", (event) => {
if (["ArrowUp", "ArrowDown", ""].includes(event.key)) {
event.preventDefault();
}
});
// This is a fix for handling visibility change
// on webview, it's for an issue reported for Samsung App.
document.addEventListener("visibilitychange", () => {
if (document.visibilityState) {
if (document.visibilityState === "hidden") {
application.publishEvent("OnWebDocumentPause", "True");
} else if (document.visibilityState === "visible") {
application.publishEvent("OnWebDocumentPause", "False");
}
}
});
// Disable context menu appearing after right click outside of the canvas.
document.addEventListener("contextmenu", (event) => event.preventDefault());