GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(core): Resolve relative URLs when enhancing fetch error messages by kunal649 · Pull Request #25555 · getsentry/sentry-javascript

fix(core): Resolve relative URLs when enhancing fetch error messages #25555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
s1gr1d merged 6 commits into getsentry:develop from kunal649:kunal/fix/fetch-error-relative-url
Oct 23, 2026
+53 −8
Merged

fix(core): Resolve relative URLs when enhancing fetch error messages #25555

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
6 commits
Select commit Hold shift + click to select a range
4400eeb
fix(core): Resolve relative URLs when enhancing fetch error messages
kunal649 Oct 20, 2026
28942cc
test: unit tests added for relative URL, an empty URL, no , a page, …
kunal649 Oct 20, 2026
be0b69e
fix(core): Resolve relative URLs when enhancing fetch error messages
kunal649 Oct 20, 2026
6478625
test(core): add sandboxed iframe test cases for fetch
kunal649 Oct 21, 2026
8e16760
Merge branch 'develop' into kunal/fix/fetch-error-relative-url
s1gr1d Oct 23, 2026
2a2cfbd
Merge branch 'develop' into kunal/fix/fetch-error-relative-url
s1gr1d Oct 23, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

18 changes: 10 additions & 8 deletions 18 packages/core/src/instrument/fetch.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,18 @@ function instrumentFetch(onFetchResolved?: (response: Response) => void): void {
error.message === 'NetworkError when attempting to fetch resource.')
) {
try {
const url = new URL(handlerData.fetchData.url);
const url = new URL(handlerData.fetchData.url, GLOBAL_OBJ.location?.href);
const hostname = url.host;

if (enhanceOption === 'always') {
// Modify the error message directly
error.message = `${error.message} (${hostname})`;
} else {
// Store hostname as non-enumerable property for Sentry-only enhancement
// This preserves the original error message for third-party packages
addNonEnumerableProperty(error, '__sentry_fetch_url_host__', hostname);
if (hostname) {
if (enhanceOption === 'always') {
// Modify the error message directly
error.message = `${error.message} (${hostname})`;
} else {
// Store hostname as non-enumerable property for Sentry-only enhancement
// This preserves the original error message for third-party packages
addNonEnumerableProperty(error, '__sentry_fetch_url_host__', hostname);
}
}
} catch {
// ignore it if errors happen here
Expand Down
1 change: 1 addition & 0 deletions 1 packages/core/src/utils/worldwide.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type { SdkSource } from './env';
/** Internal global with common properties and Sentry extensions */
export type InternalGlobal = {
navigator?: { userAgent?: string; maxTouchPoints?: number };
location?: { href?: string };
console: Console;
PerformanceObserver?: any;
Sentry?: any;
Expand Down
42 changes: 42 additions & 0 deletions 42 packages/core/test/lib/instrument/fetch.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,46 @@ describe('instrument > addFetchInstrumentationHandler', () => {

expect(error.message).toBe('Failed to fetch (example.com)');
});

describe('relative URLs', () => {
const globalWithLocation = GLOBAL_OBJ as typeof GLOBAL_OBJ & { location?: { href: string } };

afterEach(() => {
Reflect.deleteProperty(globalWithLocation, 'location');
});

async function failWith(target: string): Promise<TypeError> {
const error = new TypeError('Failed to fetch');
globalThis.fetch = vi.fn<typeof fetch>().mockRejectedValue(error);
addFetchInstrumentationHandler(() => undefined);
await expect(globalThis.fetch(target)).rejects.toBe(error);
return error;
}

it.each([
['a relative path', 'https://app.example.com/some/page?x=1', '/api/users', 'Failed to fetch (app.example.com)'],
['an empty URL (`fetch("")`)', 'https://app.example.com/some/page?x=1', '', 'Failed to fetch (app.example.com)'],
['a relative path with no current page', undefined, '/api/users', 'Failed to fetch'],
['a relative path on a `file://` page', 'file:///C:/app/index.html', '/api/users', 'Failed to fetch'],
['a relative path in a sandboxed srcdoc iframe', 'about:srcdoc', '/api/users', 'Failed to fetch'],
[
'an absolute URL in a sandboxed srcdoc iframe',
'about:srcdoc',
'https://api.example.org/v1/users',
'Failed to fetch (api.example.org)',
],
[
'an absolute URL, ignoring the current page',
'https://app.example.com/some/page',
'https://other.example.org/x',
'Failed to fetch (other.example.org)',
],
Comment thread
kunal649 marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

])('handles %s', async (_name, href, target, expected) => {
if (href) {
globalWithLocation.location = { href };
}

expect((await failWith(target)).message).toBe(expected);
});
});
});
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.