MCPcopy Create free account
hub / github.com/getsentry/sentry-javascript / parseXhrUrlArg

Function parseXhrUrlArg

packages/browser-utils/src/instrument/xhr.ts:165–177  ·  view source on GitHub ↗

* Parses the URL argument of a XHR method to a string. * * See: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/open#url * url: A string or any other object with a stringifier — including a URL object — that provides the URL of the resource to send the request to. * * @param url

(url: unknown)

Source from the content-addressed store, hash-verified

163 * @returns The parsed URL string or undefined if the URL is invalid
164 */
165function parseXhrUrlArg(url: unknown): string | undefined {
166 if (isString(url)) {
167 return url;
168 }
169
170 try {
171 // If the passed in argument is not a string, it should have a `toString` method as a stringifier.
172 // If that fails, we just return undefined (like in IE11 where URL is not available)
173 return (url as URL).toString();
174 } catch {} // eslint-disable-line no-empty
175
176 return undefined;
177}

Callers 1

applyFunction · 0.85

Calls 2

isStringFunction · 0.90
toStringMethod · 0.65

Tested by

no test coverage detected