MCPcopy
hub / github.com/vercel/next.js / resolveURL

Function resolveURL

packages/next-playwright/src/index.ts:105–148  ·  view source on GitHub ↗

* Resolves the URL to scope the instant navigation cookie to. Prefers * an explicit `baseURL` option, then falls back to the page's current URL. * Throws a descriptive error if neither is available (e.g. fresh page * before any navigation).

(
  page: PlaywrightPage,
  options?: { baseURL?: string }
)

Source from the content-addressed store, hash-verified

103 * before any navigation).
104 */
105function resolveURL(
106 page: PlaywrightPage,
107 options?: { baseURL?: string }
108): string {
109 const url = options?.baseURL ?? page.url()
110 if (url && url !== 'about:blank') {
111 return url
112 }
113 const error = new Error(
114 `Could not infer the base URL of the application.
115
116instant() needs to know the base URL so it can configure the
117browser before the first page load. If the page is already
118loaded, the base URL is detected automatically.
119Otherwise, you can fix this in one of two ways:
120
1211. Pass a baseURL option:
122
123 await instant(page, async () => {
124 await page.goto('http://localhost:3000')
125 // ...
126 }, { baseURL: 'http://localhost:3000' })
127
128 Tip: If you use baseURL in your Playwright config, you can
129 get it from the test fixture:
130
131 test('my test', async ({ page, baseURL }) => {
132 await instant(page, async () => {
133 // ...
134 }, { baseURL })
135 })
136
1372. Navigate to a page before calling instant():
138
139 await page.goto('http://localhost:3000')
140 await instant(page, async () => {
141 // ...
142 })`
143 )
144 // Remove resolveURL and instant from the stack trace so the error
145 // points at the caller's code.
146 Error.captureStackTrace(error, instant)
147 throw error
148}

Callers 1

instantFunction · 0.85

Calls 1

urlMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…