{"record":{"id":"9aaf5d8c0be034c1","repo":"phaserjs/phaser","slug":"no-dom-container-set-in-game-config","errorCode":null,"errorMessage":"No DOM Container set in game config","messagePattern":"No DOM Container set in game config","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/gameobjects/domelement/DOMElement.js","lineNumber":135,"sourceCode":"\n    initialize:\n\n    function DOMElement (scene, x, y, element, style, innerText)\n    {\n        GameObject.call(this, scene, 'DOMElement');\n\n        /**\n         * A reference to the parent DOM Container that the Game instance created when it started.\n         *\n         * @name Phaser.GameObjects.DOMElement#parent\n         * @type {Element}\n         * @since 3.17.0\n         */\n        this.parent = scene.sys.game.domContainer;\n\n        if (!this.parent)\n        {\n            throw new Error('No DOM Container set in game config');\n        }\n\n        /**\n         * A reference to the HTML Cache.\n         *\n         * @name Phaser.GameObjects.DOMElement#cache\n         * @type {Phaser.Cache.BaseCache}\n         * @since 3.17.0\n         */\n        this.cache = scene.sys.cache.html;\n\n        /**\n         * The actual DOM Element that this Game Object is bound to. For example, if you've created a `<div>`\n         * then this property is a direct reference to that element within the dom.\n         *\n         * @name Phaser.GameObjects.DOMElement#node\n         * @type {Element}\n         * @since 3.17.0","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/phaserjs/phaser/blob/41be1e462bc600064e498cba370bfa8c5c055a22/src/gameobjects/domelement/DOMElement.js#L117-L153","documentation":"DOMElement.js:135 reads `scene.sys.game.domContainer`; if it is null, Phaser did not create the DOM container and throws. The container is only created when `dom.createContainer: true` is set in the game config (Config.js:209, default false). DOMElement objects must live inside that div to be positioned over/under the canvas.","triggerScenarios":"Instantiating `this.add.dom(x, y, element)` (or `new DOMElement(scene, x, y, element)`) in a scene while the game config omits `dom: { createContainer: true }`. The DOMElementFactory and DOMElement docs both require this config.","commonSituations":"Following a DOM-element tutorial without copying the config block; enabling DOM elements mid-project and forgetting the global config; running where the parent element selector resolves but the container was never made.","solutions":["Add `dom: { createContainer: true }` to the Phaser.Game config object before any DOMElement is created.","Optionally set `dom: { createContainer: true, behindCanvas: true }` to control z-ordering relative to the canvas.","Restart the game instance after changing config (config is read once at boot)."],"exampleFix":"// before\nnew Phaser.Game({ width: 800, height: 600, scene: MyScene })\n// after\nnew Phaser.Game({ width: 800, height: 600, dom: { createContainer: true }, scene: MyScene })","handlingStrategy":"validation","validationCode":"const needsDom = sceneConfigUsesDomElements\nif (needsDom && !gameConfig.dom?.createContainer) {\n  throw new Error('Enable dom.createContainer in game config before using DOMElement')\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set `dom: { createContainer: true }` in the top-level game config whenever DOMElement usage is planned.","Centralise game config so the dom flag is set once and visibly.","Add an assertion in a scene's init that `this.sys.game.domContainer` exists before creating DOM elements."],"tags":["dom","config","domelement","startup"],"backgroundTag":null,"analyzedSha":"41be1e462bc600064e498cba370bfa8c5c055a22","analyzedAt":"2026-08-13T04:23:39.729Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}