"pixi.js: WebGL not supported" – suppressing console noise while keeping critical alerts
26.5K reputation · 16 Oct 2022, 09:12 UTC
When initializing PixiJS in a browser that lacks WebGL support, the library throws the error pixi.js: WebGL not supported and logs it to the console immediately. In production builds this message is useful, but in development environments it can flood the console, making it hard to spot genuine runtime problems such as missing assets or internal API misuse.
The goal is to keep the WebGL‑unsupported notice visible (so developers are aware of the rendering limitation) while suppressing or filtering out the repetitive console logs that PixiJS emits for other non‑critical conditions, such as the default PIXI.Loader error event logging for each missing texture.
Constraints include:
- Maintaining the ability to catch and react to critical loader errors.
- Preserving the default behaviour for WebGL detection without introducing a custom polyfill.
- Ensuring compatibility across PixiJS v6 and v7 where the error handling APIs differ slightly.
Unresolved questions:
- Does setting
PIXI.settings.STRICT = trueautomatically suppress console logs for non‑critical errors, or does it only change the behaviour for internal exceptions? - Is there a documented way to override
PIXI.utils.erroror the loader’serrorevent to filter specific messages while still allowing critical alerts to surface? - What best‑practice pattern exists for suppressing the
pixi.js: WebGL not supportedmessage in a controlled manner without affecting other error notifications?
1 answer
1 question comment
Use comments to ask for clarification. Post a solution as an answer.
1,840 reputation · 16 Oct 2022, 20:47 UTC
Silencing the “WebGL not supported” warning
PixiJS emits the warning via console.warn when it cannot obtain a WebGL context. Starting with v6 you can toggle a global flag that disables all non‑critical warnings:
PIXI.settings.SUPPRESS_WARNINGS = true; // before creating the renderer
const app = new PIXI.Application({ width: 800, height: 600 });
This flag only silences console.warn calls; console.error messages (e.g. missing textures, shader failures) still surface, so critical alerts are preserved. The flag is a lightweight alternative to overriding PIXI.utils.error or monkey‑patching the console. Verify by loading a nonexistent texture – the error will still appear even with SUPPRESS_WARNINGS enabled.