Skip to content

Commit 6acce40

Browse files
authored
fix: Exclude Base64 images from image worker handling (#500)
In Chrome versions before 67, data: URLs were treated as uncertain-origin resources for security reasons. In this context: XMLHttpRequest did not allow access to base64 (data:) URLs because it violated CORS (Cross-Origin Resource Sharing) policies. Even though a data: URL is "local," it was still considered a different origin from the domain where the request was made.
2 parents 88ed685 + 9e59a1b commit 6acce40

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/core/lib/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,7 @@ export function convertUrlToAbsolute(url: string): string {
304304
const absoluteUrl = new URL(url, self.location.href);
305305
return absoluteUrl.href;
306306
}
307+
308+
export function isBase64Image(src: string) {
309+
return src.startsWith('data:') === true;
310+
}

src/core/textures/ImageTexture.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
isCompressedTextureContainer,
2424
loadCompressedTexture,
2525
} from '../lib/textureCompression.js';
26-
import { convertUrlToAbsolute } from '../lib/utils.js';
26+
import { convertUrlToAbsolute, isBase64Image } from '../lib/utils.js';
2727
import { isSvgImage, loadSvg } from '../lib/textureSvg.js';
2828

2929
/**
@@ -135,7 +135,7 @@ export class ImageTexture extends Texture {
135135
async loadImageFallback(src: string, hasAlpha: boolean) {
136136
const img = new Image();
137137

138-
if (!src.startsWith('data:')) {
138+
if (isBase64Image(src) === false) {
139139
img.crossOrigin = 'anonymous';
140140
}
141141

@@ -206,6 +206,7 @@ export class ImageTexture extends Texture {
206206

207207
if (this.txManager.hasCreateImageBitmap === true) {
208208
if (
209+
isBase64Image(src) === false &&
209210
this.txManager.hasWorker === true &&
210211
this.txManager.imageWorkerManager !== null
211212
) {

0 commit comments

Comments
 (0)