Per CHANGELOG, since Version 3.53.0 phaser3 is preventing `AudioContext was not allowed` warnings, but I still encounter it, how do I do?

Viewed 93

Per the CHANGELOG, since Version 3.53.0 - Anastasia - 8th March 2021

SceneManager.loadComplete will no longer try to unlock the Sound Manager, preventing AudioContext was not allowed to start console warnings after each Scene finishes loading.

However, each time I run a phaser3 app on Chrome 96.0.4664.110 (Official Build) (x86_64)

var game = new Phaser.Game();
<script src="https://cdn.jsdelivr.net/npm/phaser@3.55.2/dist/phaser.js"></script>

I still get that annoying warning.

enter image description here

Am I missing something?

1 Answers

The problem is, that this is a browser "issue" (look at this link, for a chromium example: https://bugs.chromium.org/p/chromium/issues/detail?id=943258#c6)
the browser, outputs this warning, if you create an AudioContext without user interaction. Phaser creates an AudioContext on creating a Phaser Game Object new Phaser.Game(...);.

If you want to get rid of the Warning message, I have two different ideas, how you could do this:

Option 1:
Make a simple html-page with a start button/image/... and only create the Phaser.Game Object after a user iteraction, then there would be no Warning. (this is "cleaner", abit of overhead)

let button = document.querySelector('#btnStart');

button.addEventListener('click', () => {
    var game = new Phaser.Game();
});
<script src="https://cdn.jsdelivr.net/npm/phaser@3.55.2/dist/phaser.js"></script>
<button id="btnStart"> Start </button>

Option 2:
Or you could clear the console, with console.clear(); after creating the object. (easy quick fix)

var game = new Phaser.Game();
console.clear();
<script src="https://cdn.jsdelivr.net/npm/phaser@3.55.2/dist/phaser.js"></script>

Just so that you know the Warning has no effect, a can be ignored.

Related