Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(nextjs): Set url attributes on pageload and navigation spans#22006
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.
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
0beefb5601bb18a6ac3d07328c5cfd7fcedd562438File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { WINDOW } from '../types'; | ||
| /** | ||
| * | ||
| * @param urlOrPath - The URL or path to convert to an absolute URL. | ||
| * | ||
| * @return the absolute URL when handed a relative URL path, by | ||
| * combining the current `window.location.origin` with param urlOrPath. | ||
| * | ||
| * If param urlOrPath is already a full or an invalid URL, | ||
| * or URL determination fails, the original param urlOrPath is returned unchanged. | ||
| * | ||
| */ | ||
| export function getAbsoluteUrl(urlOrPath: string): string { | ||
| try { | ||
| const url = new URL(urlOrPath, WINDOW.location.origin); | ||
| return url.toString(); | ||
| } catch { | ||
| // fallback, just do nothing | ||
| return urlOrPath; | ||
| } | ||
cursor[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { describe, it, expect, beforeEach, vi } from 'vitest'; | ||
| import { getAbsoluteUrl } from '../../src/instrument/location'; | ||
| describe('getAbsoluteUrl', () => { | ||
| beforeEach(() => { | ||
| vi.stubGlobal('location', { | ||
| origin: 'https://sentry.io', | ||
| }); | ||
| }); | ||
| it('returns the absolute URL when handed a relative URL', () => { | ||
| expect(getAbsoluteUrl('/foo')).toBe('https://sentry.io/foo'); | ||
| }); | ||
| it('returns the original URL when handed a full URL', () => { | ||
| expect(getAbsoluteUrl('https://santry.io/foo')).toBe('https://santry.io/foo'); | ||
| }); | ||
| it('returns query params', () => { | ||
| expect(getAbsoluteUrl('/foo?bar=baz')).toBe('https://sentry.io/foo?bar=baz'); | ||
| }); | ||
| it('returns fragments', () => { | ||
| expect(getAbsoluteUrl('/foo#bar')).toBe('https://sentry.io/foo#bar'); | ||
| }); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.