Unverified Commit af42dadd authored by Hendrik Liebau's avatar Hendrik Liebau Committed by GitHub

Allow `beforePageLoad` to be async (#81650)

parent 3c6591c1
...@@ -81,16 +81,17 @@ describe('segment cache (staleness)', () => { ...@@ -81,16 +81,17 @@ describe('segment cache (staleness)', () => {
it('reuses dynamic data up to the staleTimes.dynamic threshold', async () => { it('reuses dynamic data up to the staleTimes.dynamic threshold', async () => {
let page: Playwright.Page let page: Playwright.Page
const startDate = Date.now()
const browser = await next.browser('/', { const browser = await next.browser('/', {
beforePageLoad(p: Playwright.Page) { async beforePageLoad(p: Playwright.Page) {
page = p page = p
await page.clock.install()
await page.clock.setFixedTime(startDate)
}, },
}) })
const act = createRouterAct(page)
await page.clock.install() const act = createRouterAct(page)
const startDate = Date.now()
await page.clock.setFixedTime(startDate)
// Navigate to the dynamic page // Navigate to the dynamic page
await act( await act(
......
...@@ -228,7 +228,7 @@ export class Playwright<TCurrent = undefined> { ...@@ -228,7 +228,7 @@ export class Playwright<TCurrent = undefined> {
disableCache?: boolean disableCache?: boolean
cpuThrottleRate?: number cpuThrottleRate?: number
pushErrorAsConsoleLog?: boolean pushErrorAsConsoleLog?: boolean
beforePageLoad?: (page: Page) => void beforePageLoad?: (page: Page) => void | Promise<void>
} }
) { ) {
await this.close() await this.close()
...@@ -310,7 +310,7 @@ export class Playwright<TCurrent = undefined> { ...@@ -310,7 +310,7 @@ export class Playwright<TCurrent = undefined> {
}) })
}) })
opts?.beforePageLoad?.(page) await opts?.beforePageLoad?.(page)
await page.goto(url, { waitUntil: 'load' }) await page.goto(url, { waitUntil: 'load' })
} }
......
...@@ -703,8 +703,8 @@ export class NextInstance { ...@@ -703,8 +703,8 @@ export class NextInstance {
const [browser, response] = await Promise.all([ const [browser, response] = await Promise.all([
webdriver(this.url, url, { webdriver(this.url, url, {
...options, ...options,
beforePageLoad(page: Page) { async beforePageLoad(page: Page) {
options.beforePageLoad?.(page) await options.beforePageLoad?.(page)
page.on('response', async (response) => { page.on('response', async (response) => {
if (response.url() === absoluteUrl) { if (response.url() === absoluteUrl) {
......
...@@ -62,7 +62,7 @@ export interface WebdriverOptions { ...@@ -62,7 +62,7 @@ export interface WebdriverOptions {
* @param page * @param page
* @returns * @returns
*/ */
beforePageLoad?: (page: Page) => void beforePageLoad?: (page: Page) => void | Promise<void>
/** /**
* browser locale * browser locale
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment