Enables cross-origin Web Workers (#35483)

This commit is contained in:
Echo 2025-07-24 09:14:27 +02:00 committed by GitHub
commit 7f9ad7eabf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 44 additions and 6 deletions

View file

@ -1,4 +1,5 @@
import initialState from '@/mastodon/initial_state';
import { loadWorker } from '@/mastodon/utils/workers';
import { toSupportedLocale } from './locale';
@ -9,9 +10,8 @@ let worker: Worker | null = null;
export async function initializeEmoji() {
if (!worker && 'Worker' in window) {
try {
worker = new Worker(new URL('./worker', import.meta.url), {
worker = loadWorker(new URL('./worker', import.meta.url), {
type: 'module',
credentials: 'omit',
});
} catch (err) {
console.warn('Error creating web worker:', err);

View file

@ -36,15 +36,16 @@ async function fetchAndCheckEtag<ResultType extends object[]>(
): Promise<ResultType | null> {
const locale = toSupportedLocaleOrCustom(localeOrCustom);
let uri: string;
// Use location.origin as this script may be loaded from a CDN domain.
const url = new URL(location.origin);
if (locale === 'custom') {
uri = '/api/v1/custom_emojis';
url.pathname = '/api/v1/custom_emojis';
} else {
uri = `/packs${isDevelopment() ? '-dev' : ''}/emoji/${locale}.json`;
url.pathname = `/packs${isDevelopment() ? '-dev' : ''}/emoji/${locale}.json`;
}
const oldEtag = await loadLatestEtag(locale);
const response = await fetch(uri, {
const response = await fetch(url, {
headers: {
'Content-Type': 'application/json',
'If-None-Match': oldEtag ?? '', // Send the old ETag to check for modifications