"pixi.js: WebGL not supported" – suppressing console noise while keeping critical alerts
0 reputation · 16 Oct 2022, 09:12 UTC
0 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:
Unresolved questions:
PIXI.settings.STRICT = true automatically suppress console logs for non‑critical errors, or does it only change the behaviour for internal exceptions?PIXI.utils.error or the loader’s error event to filter specific messages while still allowing critical alerts to surface?pixi.js: WebGL not supported message in a controlled manner without affecting other error notifications?28775 reputation · 16 Oct 2022, 12:59 UTC
The cleanest fix is not to filter the console at all: check WebGL support before creating the renderer, so PixiJS never reaches the code path that logs the message. For everything else, wrap console.error/console.warn once at startup with a narrow substring filter, and leave loader error events wired to your own handler so critical failures still surface.
pixi.js: WebGL not supported means the browser failed to hand PixiJS a WebGL context — a disabled GPU, blocklisted driver, headless environment, or exhausted context limit. It is an environment fact, not a bug in your scene code. Because PixiJS logs it during renderer creation, the only way to keep it from appearing is to decide before creation what to do.
In PixiJS v6/v7, PIXI.utils.isWebGLSupported() runs the same probe the renderer would. Gate initialization on it:
import * as PIXI from 'pixi.js';
if (PIXI.utils.isWebGLSupported()) {
const app = new PIXI.Application({ width: 800, height: 600 });
document.body.appendChild(app.view);
} else {
// One deliberate, visible notice — not console spam
showFallbackBanner('Your browser does not support WebGL.');
// Optional: explicit canvas fallback instead of letting autoDetect throw
// const app = new PIXI.Application({ forceCanvas: true });
}Because you branch first, the internal warning path never executes, and the user gets a controlled message instead of a console line. In v8 the renderer API changed to async Application.init() with preference: 'canvas' as the fallback option — verify against your installed version with npm list pixi.js, since the option names differ across majors.
If a dependency or test harness still triggers the message, wrap the console once, match narrowly, and forward everything else untouched:
const originalError = console.error.bind(console);
const SUPPRESSED = ['WebGL is not supported'];
console.error = (...args) => {
const first = String(args[0] ?? '');
if (SUPPRESSED.some(s => first.includes(s))) return;
originalError(...args);
};Two rules keep this safe. First, never blanket-silence console.error — shader-compile failures and texture decode errors travel the same channel and are exactly the "genuine runtime problems" you want to see. Second, keep the match list short and documented; string matching is brittle across PixiJS releases and locales.
PIXI.settings.STRICT = true suppress logs? No. STRICT changes internal behavior (stricter validation/exceptions); it is not a log-level control. Do not rely on it for console hygiene.onError handler to the loader (v6) or wrap Assets.load in try/catch (v7+). Log each failure once with the asset URL, and rethrow or escalate failures for assets your scene cannot run without. That keeps critical alerts in your control instead of PixiJS's default logging.isWebGLSupported() (or a try/catch around renderer creation) beats post-hoc filtering. Reserve console wrapping for environments you don't control, such as CI.In jsdom or headless CI, the message is expected and harmless. Gate PixiJS initialization behind the same capability check, or mock the renderer in tests, rather than filtering logs after the fact.
Losing WebGL at runtime is a different, critical event. Listen for webglcontextlost on the canvas and treat it as an alert — never route it through your suppression filter:
app.view.addEventListener('webglcontextlost', (e) => {
e.preventDefault();
notifyUser('Graphics context lost — reloading.');
});--disable-webgl and confirm your capability branch runs and no PixiJS warning appears.npm list pixi.js) matches the renderer API your code uses.Version note: option names and the loader/Assets API differ between PixiJS v6, v7, and v8; the snippets above target v6/v7 and should be checked against your installed release.
Use comments to ask for clarification. Post a solution as an answer.
2,120 reputation · 16 Oct 2022, 20:47 UTC
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.