Skip to content

Commit c89c30e

Browse files
authored
fix(popup): do not report frameless pages (#2910)
1 parent c21b637 commit c89c30e

File tree

10 files changed

+41
-9
lines changed

10 files changed

+41
-9
lines changed

src/chromium/crBrowser.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,15 @@ export class CRBrowser extends BrowserBase {
151151
const opener = targetInfo.openerId ? this._crPages.get(targetInfo.openerId) || null : null;
152152
const crPage = new CRPage(session, targetInfo.targetId, context, opener, !!this._options.headful);
153153
this._crPages.set(targetInfo.targetId, crPage);
154-
crPage.pageOrError().then(() => {
155-
context!.emit(CommonEvents.BrowserContext.Page, crPage._page);
154+
crPage.pageOrError().then(pageOrError => {
155+
const page = crPage._page;
156+
if (pageOrError instanceof Error)
157+
page._setIsError();
158+
context!.emit(CommonEvents.BrowserContext.Page, page);
156159
if (opener) {
157160
opener.pageOrError().then(openerPage => {
158161
if (openerPage instanceof Page && !openerPage.isClosed())
159-
openerPage.emit(CommonEvents.Page.Popup, crPage._page);
162+
openerPage.emit(CommonEvents.Page.Popup, page);
160163
});
161164
}
162165
});

src/firefox/ffBrowser.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,10 @@ export class FFBrowser extends BrowserBase {
9797
const ffPage = new FFPage(session, context, opener);
9898
this._ffPages.set(targetId, ffPage);
9999

100-
ffPage.pageOrError().then(async () => {
100+
ffPage.pageOrError().then(async pageOrError => {
101101
const page = ffPage._page;
102+
if (pageOrError instanceof Error)
103+
page._setIsError();
102104
context.emit(Events.BrowserContext.Page, page);
103105
if (!opener)
104106
return;

src/page.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,11 @@ export class Page extends EventEmitter {
490490
await this._ownedContext.close();
491491
}
492492

493+
_setIsError() {
494+
if (!this._frameManager.mainFrame())
495+
this._frameManager.frameAttached('<dummy>', null);
496+
}
497+
493498
isClosed(): boolean {
494499
return this._closedState === 'closed';
495500
}

src/rpc/channels.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ export interface PageChannel extends Channel {
167167

168168
export type PageInitializer = {
169169
mainFrame: FrameChannel,
170-
viewportSize: types.Size | null
170+
viewportSize: types.Size | null,
171+
isClosed: boolean
171172
};
172173

173174
export type PageAttribution = { isPage?: boolean };

src/rpc/client/page.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export class Page extends ChannelOwner<PageChannel, PageInitializer> {
8080
this._mainFrame._page = this;
8181
this._frames.add(this._mainFrame);
8282
this._viewportSize = initializer.viewportSize;
83+
this._closed = initializer.isClosed;
8384

8485
this._channel.on('bindingCall', bindingCall => this._onBinding(BindingCall.from(bindingCall)));
8586
this._channel.on('close', () => this._onClose());

src/rpc/server/pageDispatcher.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ export class PageDispatcher extends Dispatcher<Page, PageInitializer> implements
3939
constructor(scope: DispatcherScope, page: Page) {
4040
super(scope, page, 'page', {
4141
mainFrame: FrameDispatcher.from(scope, page.mainFrame()),
42-
viewportSize: page.viewportSize()
42+
viewportSize: page.viewportSize(),
43+
isClosed: page.isClosed()
4344
});
4445
this._page = page;
4546
page.on(Events.Page.Close, () => this._dispatchEvent('close'));

src/webkit/wkBrowser.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,10 @@ export class WKBrowser extends BrowserBase {
140140
const wkPage = new WKPage(context, pageProxySession, opener || null);
141141
this._wkPages.set(pageProxyId, wkPage);
142142

143-
wkPage.pageOrError().then(async () => {
143+
wkPage.pageOrError().then(async pageOrError => {
144144
const page = wkPage._page;
145+
if (pageOrError instanceof Error)
146+
page._setIsError();
145147
context!.emit(Events.BrowserContext.Page, page);
146148
if (!opener)
147149
return;

test/browsercontext.spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,23 @@ describe('BrowserContext', function() {
129129
]);
130130
await context.close();
131131
});
132+
it('should not report frameless pages on error', async({browser, server}) => {
133+
const context = await browser.newContext();
134+
page = await context.newPage();
135+
server.setRoute('/empty.html', (req, res) => {
136+
res.end(`<a href="${server.EMPTY_PAGE}" target="_blank">Click me</a>`);
137+
});
138+
let popup;
139+
context.on('page', p => popup = p);
140+
await page.goto(server.EMPTY_PAGE);
141+
await page.click('"Click me"');
142+
await context.close();
143+
if (popup) {
144+
// This races on Firefox :/
145+
expect(popup.isClosed()).toBeTruthy();
146+
expect(popup.mainFrame()).toBeTruthy();
147+
}
148+
})
132149
});
133150

134151
describe('BrowserContext({userAgent})', function() {

test/channels.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe.skip(!CHANNEL)('Channels', function() {
4848
await expectScopeState(browser, GOLDEN_PRECONDITION);
4949
});
5050

51-
it('should scope CDPSession handles', async({browserType, browser, server}) => {
51+
it.skip(!CHROMIUM)('should scope CDPSession handles', async({browserType, browser, server}) => {
5252
const GOLDEN_PRECONDITION = {
5353
objects: [ 'chromium', 'firefox', 'webkit', 'playwright', 'browser' ],
5454
scopes: [

test/page.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ describe('Async stacks', () => {
113113
});
114114
});
115115

116-
describe.fail(FFOX && WIN)('Page.Events.Crash', function() {
116+
describe.fail(FFOX && WIN).skip(CHANNEL)('Page.Events.Crash', function() {
117117
// Firefox Win: it just doesn't crash sometimes.
118118

119119
function crash(page) {

0 commit comments

Comments
 (0)