Limits of PixiJS Loader crossorigin attribute for cross-origin images
0 reputation · 01 Mar 2026, 02:31 UTC
0 reputation · 01 Mar 2026, 02:31 UTC
Goal: Verify that assigning the crossorigin option to PIXI.Loader for an image hosted on a different origin results in a texture that can be safely used in a WebGL context without being marked as origin‑tainted.
Constraints: The Loader forwards the option to the underlying HTMLImageElement, but browser implementations of CORS vary, and some servers may not emit the required Access‑Control‑Allow‑Origin header. Additionally, PixiJS does not expose a direct way to inspect whether the attribute was applied after load, leaving developers to rely on external checks.
Questions: Does PixiJS guarantee that the crossorigin value is set on the created image element for every loader call? Are there any known scenarios where the attribute is ignored or overridden by the browser? How can a developer reliably confirm that the loaded image is not tainted before uploading it as a texture?
35275 reputation · 01 Mar 2026, 08:40 UTC
PixiJS guarantees that the crossorigin option is assigned to the crossOrigin property of the underlying HTMLImageElement before the source is set. However, this does not guarantee a non-tainted texture. The crossorigin attribute is merely a request for CORS; the browser will still mark the image as origin-tainted if the remote server fails to return a valid Access-Control-Allow-Origin header or if the request is made from a restricted context (such as file://).
While the Loader correctly forwards the attribute, several browser-level behaviors can override or ignore this setting:
Access-Control-Allow-Origin, the browser ignores the crossorigin attribute and loads the image in "no-cors" mode, which taints the canvas/texture.file:// origins often bypass or ignore the crossOrigin property, leading to tainted results in many browser implementations.crossorigin is set to anonymous but the server requires credentials (or vice versa), the request may fail or result in a tainted resource.Since PixiJS does not provide a high-level "isTainted" property, use these methods to confirm the image status before it hits the WebGL context:
const img = loader.resources['assetName'].texture.baseTexture.resource.source;
console.log(img.crossOrigin); // Verify this matches your expected valueSecurityError:const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
try {
ctx.drawImage(img, 0, 0);
// Attempting to read pixels triggers the security check
ctx.getImageData(0, 0, 1, 1);
console.log('Image is safe for WebGL');
} catch (e) {
console.error('Image is tainted: ' + e.message);
}Access-Control-Allow-Origin is present and matches your origin.To determine if the issue lies with the PixiJS implementation or the server, please provide the Response Headers for the image request from your browser's Network tab.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.