Files
openobserve/web/src/workers/rumcssworker.js
T
Omkar Kesarkhaneandgithub-actions[bot] 5f6f8b84c7 perf(rum): progressive session replay loading, load states and live sessions (#14956)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-09-30 17:57:09 +00:00

27 lines
922 B
JavaScript

self.addEventListener("message", (e) => {
const cssString = e.data.cssString;
const proxyUrl = e.data.proxyUrl;
const id = e.data.id;
const updatedCssString = replaceAbsoluteUrlsWithProxies(proxyUrl, cssString, [
"fonts.gstatic.com",
"fonts.googleapis.com",
]);
self.postMessage({ updatedCssString, id });
});
function replaceAbsoluteUrlsWithProxies(proxyUrl, cssString, excludedDomains = []) {
const urlRegex = /url\(\s*(['"]?)(https?:\/\/[^'")]+)\1\s*\)/g;
function replaceWithProxy(match, t1, url) {
// Stored records are shared with every later conversion, so a second pass must not proxy a proxied URL again.
if (url.startsWith(proxyUrl)) return match;
const isExcluded = excludedDomains.some((domain) => url.includes(domain));
if (isExcluded) {
return match;
}
return `url("${proxyUrl}/${url}")`;
}
return cssString.replace(urlRegex, replaceWithProxy);
}