From 986a41781af4e6c89364eded9cb8a6ebcb49b9c4 Mon Sep 17 00:00:00 2001 From: Stefan Vukovic Date: Sat, 3 Feb 2024 22:53:52 +0100 Subject: [PATCH] undo changes to cssStyleApplier --- ext/js/dom/sandbox/css-style-applier.js | 26 +++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/ext/js/dom/sandbox/css-style-applier.js b/ext/js/dom/sandbox/css-style-applier.js index a1c33822e7..ea3f1a28e7 100644 --- a/ext/js/dom/sandbox/css-style-applier.js +++ b/ext/js/dom/sandbox/css-style-applier.js @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -import {fetchJson} from '../../core/fetch-utilities.js'; +import {readResponseJson} from '../../core/json.js'; /** * This class is used to apply CSS styles to elements using a consistent method @@ -48,7 +48,7 @@ export class CssStyleApplier { /** @type {import('css-style-applier').RawStyleData} */ let rawData = []; try { - rawData = await fetchJson(this._styleDataUrl); + rawData = await this._fetchJsonAsset(this._styleDataUrl); } catch (e) { // eslint-disable-next-line no-console console.error(e); @@ -98,6 +98,28 @@ export class CssStyleApplier { // Private + /** + * Fetches and parses a JSON file. + * @template [T=unknown] + * @param {string} url The URL to the file. + * @returns {Promise} A JSON object. + * @throws {Error} An error is thrown if the fetch fails. + */ + async _fetchJsonAsset(url) { + const response = await fetch(url, { + method: 'GET', + mode: 'no-cors', + cache: 'default', + credentials: 'omit', + redirect: 'follow', + referrerPolicy: 'no-referrer' + }); + if (!response.ok) { + throw new Error(`Failed to fetch ${url}: ${response.status}`); + } + return await readResponseJson(response); + } + /** * Gets an array of candidate CSS rules which might match a specific class. * @param {string} className A whitespace-separated list of classes.