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

Method loadPage

test/lib/browsers/playwright.ts:266–372  ·  view source on GitHub ↗
(
    url: string,
    opts?: {
      disableCache?: boolean
      cpuThrottleRate?: number
      pushErrorAsConsoleLog?: boolean
      beforePageLoad?: (page: Page) => void | Promise<void>
      /**
       * @see {@link https://playwright.dev/docs/api/class-page#page-set-extra-http-headers Playwright.Page.setExtraHTTPHeaders}
       */
      extraHTTPHeaders?: Record<string, string>
      waitUntil?: PlaywrightNavigationWaitUntil
    }
  )

Source from the content-addressed store, hash-verified

264 }
265
266 async loadPage(
267 url: string,
268 opts?: {
269 disableCache?: boolean
270 cpuThrottleRate?: number
271 pushErrorAsConsoleLog?: boolean
272 beforePageLoad?: (page: Page) => void | Promise<void>
273 /**
274 * @see {@link https://playwright.dev/docs/api/class-page#page-set-extra-http-headers Playwright.Page.setExtraHTTPHeaders}
275 */
276 extraHTTPHeaders?: Record<string, string>
277 waitUntil?: PlaywrightNavigationWaitUntil
278 }
279 ) {
280 await this.close()
281
282 // clean-up existing pages
283 for (const oldPage of context!.pages()) {
284 await oldPage.close()
285 }
286
287 await this.initContextTracing(url, context!)
288 page = await context!.newPage()
289
290 page.setDefaultTimeout(defaultTimeout)
291 page.setDefaultNavigationTimeout(defaultTimeout)
292 const extraHTTPHeaders = opts?.extraHTTPHeaders
293 if (extraHTTPHeaders !== undefined) {
294 page.setExtraHTTPHeaders(extraHTTPHeaders)
295 }
296
297 pageLogs = []
298 websocketFrames = []
299
300 page.on('console', (msg) => {
301 debugPrint('Browser Log:', msg)
302
303 pageLogs.push(
304 Promise.all(
305 msg.args().map((handle) => handle.jsonValue().catch(() => {}))
306 ).then((args) => ({ source: msg.type(), message: msg.text(), args }))
307 )
308 })
309 page.on('crash', () => {
310 console.error('page crashed')
311 })
312 page.on('pageerror', (error) => {
313 console.error('page error', error)
314
315 if (opts?.pushErrorAsConsoleLog) {
316 pageLogs.push({ source: 'error', message: error.message, args: [] })
317 }
318 })
319 page.on('request', (req) => {
320 this.eventCallbacks.request.forEach((cb) => cb(req))
321 })
322 page.on('response', (res) => {
323 this.eventCallbacks.response.forEach((cb) => cb(res))

Callers 15

webdriverFunction · 0.95
testInitialLoadFunction · 0.45
testNavigationFunction · 0.45
testInitialLoadFunction · 0.45
testNavigationFunction · 0.45
hmr.test.tsFile · 0.45
use-cache.test.tsFile · 0.45
rsc-basic.test.tsFile · 0.45

Calls 15

closeMethod · 0.95
initContextTracingMethod · 0.95
debugPrintFunction · 0.90
thenMethod · 0.80
allMethod · 0.80
decodeMethod · 0.80
beforePageLoadMethod · 0.80
closeMethod · 0.65
pushMethod · 0.65
textMethod · 0.65
errorMethod · 0.65
sendMethod · 0.65

Tested by 4

testInitialLoadFunction · 0.36
testNavigationFunction · 0.36
testInitialLoadFunction · 0.36
testNavigationFunction · 0.36