Skip to content

Commit

Permalink
fix(reuse): make sure newly created page is not "server-side-only" (#…
Browse files Browse the repository at this point in the history
…26332)

This page is going to be the "page for reuse", so it should not be
marked as "server-side-only" and should issue all required events.

Fixes #24574.
  • Loading branch information
dgozman authored Aug 7, 2023
1 parent 90c765d commit 9509c30
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/playwright-core/src/server/browserContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,12 @@ export abstract class BrowserContext extends SdkObject {
let page = this.pages()[0];

const internalMetadata = serverSideCallMetadata();
page = page || await this.newPage(internalMetadata);
page = page || await this.newPage({
...internalMetadata,
// Do not mark this page as internal, because we will leave it for later reuse
// as a user-visible page.
isServerSide: false,
});
await page._setServerRequestInterceptor(handler => {
handler.fulfill({ body: '<html></html>', requestUrl: handler.request().url() }).catch(() => {});
return true;
Expand Down
22 changes: 22 additions & 0 deletions tests/library/browsercontext-reuse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,25 @@ test('should reset tracing', async ({ reusedContext, trace }, testInfo) => {
const error = await context.tracing.stopChunk({ path: testInfo.outputPath('trace.zip') }).catch(e => e);
expect(error.message).toContain('tracing.stopChunk: Must start tracing before stopping');
});

test('should continue issuing events after closing the reused page', async ({ reusedContext, server }) => {
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/24574' });

{
const context = await reusedContext();
const page = await context.newPage();
await Promise.all([
page.waitForRequest(server.PREFIX + '/one-style.css'),
page.goto(server.PREFIX + '/one-style.html'),
]);
await page.close();
}
{
const context = await reusedContext();
const page = context.pages()[0];
await Promise.all([
page.waitForRequest(server.PREFIX + '/one-style.css', { timeout: 10000 }),
page.goto(server.PREFIX + '/one-style.html'),
]);
}
});

0 comments on commit 9509c30

Please sign in to comment.