Skip to content

Commit

Permalink
feat(webdriver): support for PageEvent.Popup (puppeteer#12612)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Rudenko <OrKoN@users.noreply.github.com>
  • Loading branch information
Lightning00Blade and OrKoN authored Jun 18, 2024
1 parent 6609758 commit 293926b
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 60 deletions.
9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/puppeteer-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
"license": "Apache-2.0",
"dependencies": {
"@puppeteer/browsers": "2.2.3",
"chromium-bidi": "0.5.23",
"chromium-bidi": "0.5.24",
"debug": "4.3.5",
"devtools-protocol": "0.0.1299070",
"ws": "8.17.1"
Expand Down
16 changes: 15 additions & 1 deletion packages/puppeteer-core/src/bidi/BrowserContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,21 @@ export class BidiBrowserContext extends BrowserContext {
}

this.userContext.on('browsingcontext', ({browsingContext}) => {
this.#createPage(browsingContext);
const page = this.#createPage(browsingContext);

// We need to wait for the DOMContentLoaded as the
// browsingContext still may be navigating from the about:blank
browsingContext.once('DOMContentLoaded', () => {
if (browsingContext.originalOpener) {
for (const context of this.userContext.browsingContexts) {
if (context.id === browsingContext.originalOpener) {
this.#pages
.get(context)!
.trustedEmitter.emit(PageEvent.Popup, page);
}
}
}
});
});
this.userContext.on('closed', () => {
this.trustedEmitter.removeAllListeners();
Expand Down
19 changes: 15 additions & 4 deletions packages/puppeteer-core/src/bidi/core/BrowsingContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,16 @@ export class BrowsingContext extends EventEmitter<{
userContext: UserContext,
parent: BrowsingContext | undefined,
id: string,
url: string
url: string,
originalOpener: string | null
): BrowsingContext {
const browsingContext = new BrowsingContext(userContext, parent, id, url);
const browsingContext = new BrowsingContext(
userContext,
parent,
id,
url,
originalOpener
);
browsingContext.#initialize();
return browsingContext;
}
Expand All @@ -140,19 +147,22 @@ export class BrowsingContext extends EventEmitter<{
readonly id: string;
readonly parent: BrowsingContext | undefined;
readonly userContext: UserContext;
readonly originalOpener: string | null;

private constructor(
context: UserContext,
parent: BrowsingContext | undefined,
id: string,
url: string
url: string,
originalOpener: string | null
) {
super();

this.#url = url;
this.id = id;
this.parent = parent;
this.userContext = context;
this.originalOpener = originalOpener;

this.defaultRealm = this.#createWindowRealm();
}
Expand All @@ -177,7 +187,8 @@ export class BrowsingContext extends EventEmitter<{
this.userContext,
this,
info.context,
info.url
info.url,
info.originalOpener
);
this.#children.set(info.context, browsingContext);

Expand Down
3 changes: 2 additions & 1 deletion packages/puppeteer-core/src/bidi/core/UserContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ export class UserContext extends EventEmitter<{
this,
undefined,
info.context,
info.url
info.url,
info.originalOpener
);
this.#browsingContexts.set(browsingContext.id, browsingContext);

Expand Down
63 changes: 14 additions & 49 deletions test/TestExpectations.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,6 @@
"expectations": ["SKIP"],
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
},
{
"testIdPattern": "[page.spec] Page Page.Events.Popup *",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["SKIP"],
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
},
{
"testIdPattern": "[page.spec] Page Page.metrics *",
"platforms": ["darwin", "linux", "win32"],
Expand Down Expand Up @@ -632,6 +625,20 @@
"expectations": ["SKIP"],
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
},
{
"testIdPattern": "[page.spec] Page Page.Events.Popup *",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["FAIL"],
"comment": "Firefox does not support originalOpener yet."
},
{
"testIdPattern": "[page.spec] Page Page.Events.Popup *",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["cdp", "firefox"],
"expectations": ["SKIP"],
"comment": "Deprecated"
},
{
"testIdPattern": "[page.spec] Page Page.exposeFunction *",
"platforms": ["darwin", "linux", "win32"],
Expand Down Expand Up @@ -2869,48 +2876,6 @@
"expectations": ["SKIP"],
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
},
{
"testIdPattern": "[page.spec] Page Page.Events.Popup should work",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["cdp", "firefox"],
"expectations": ["SKIP"],
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
},
{
"testIdPattern": "[page.spec] Page Page.Events.Popup should work with clicking target=_blank and rel=noopener",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["cdp", "firefox"],
"expectations": ["SKIP"],
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
},
{
"testIdPattern": "[page.spec] Page Page.Events.Popup should work with clicking target=_blank and with rel=opener",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["cdp", "firefox"],
"expectations": ["SKIP"],
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
},
{
"testIdPattern": "[page.spec] Page Page.Events.Popup should work with clicking target=_blank and without rel=opener",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["cdp", "firefox"],
"expectations": ["SKIP"],
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
},
{
"testIdPattern": "[page.spec] Page Page.Events.Popup should work with fake-clicking target=_blank and rel=noopener",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["cdp", "firefox"],
"expectations": ["SKIP"],
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
},
{
"testIdPattern": "[page.spec] Page Page.Events.Popup should work with noopener",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["cdp", "firefox"],
"expectations": ["SKIP"],
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
},
{
"testIdPattern": "[page.spec] Page Page.metrics metrics event fired on console.timeStamp",
"platforms": ["darwin", "linux", "win32"],
Expand Down

0 comments on commit 293926b

Please sign in to comment.