MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / stripDataUrlContent

Function stripDataUrlContent

packages/core/src/utils/url.ts:282–301  ·  view source on GitHub ↗
(url: string, includeDataPrefix: boolean = true)

Source from the content-addressed store, hash-verified

280 * For non-data URLs, returns the original URL unchanged.
281 */
282export function stripDataUrlContent(url: string, includeDataPrefix: boolean = true): string {
283 if (url.startsWith('data:')) {
284 // Match the MIME type (everything after 'data:' until the first ';' or ',')
285 const match = url.match(/^data:([^;,]+)/);
286 const mimeType = match ? match[1] : 'text/plain';
287 const isBase64 = url.includes(';base64,');
288
289 // Find where the actual data starts (after the comma)
290 const dataStart = url.indexOf(',');
291 let dataPrefix = '';
292 if (includeDataPrefix && dataStart !== -1) {
293 const data = url.slice(dataStart + 1);
294 // Include first 10 chars of data to help identify content (e.g., magic bytes)
295 dataPrefix = data.length > 10 ? `${data.slice(0, 10)}... [truncated]` : data;
296 }
297
298 return `data:${mimeType}${isBase64 ? ',base64' : ''}${dataPrefix ? `,${dataPrefix}` : ''}`;
299 }
300 return url;
301}

Callers 9

setupFunction · 0.90
url.test.tsFile · 0.90
getSpanStartOptionsFunction · 0.90
getFetchSpanAttributesFunction · 0.90
setupOnceFunction · 0.90
onRequestCreatedFunction · 0.90
getFilenameFromUrlFunction · 0.85
xhrCallbackFunction · 0.85

Calls 2

matchMethod · 0.80
sliceMethod · 0.80

Tested by

no test coverage detected