Skip to content

Commit 0b333e1

Browse files
authored
Bidi Page Event Close (#3002)
* Bidi Page Event Close * Some fixes * fiz
1 parent fb1eb8e commit 0b333e1

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectations.local.json

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -960,21 +960,6 @@
960960
"FAIL"
961961
]
962962
},
963-
{
964-
"comment": "This is part of organizing the webdriver bidi implementation, We will remove it one by one",
965-
"testIdPattern": "[page.spec] *Page.Events.Close*",
966-
"platforms": [
967-
"darwin",
968-
"linux",
969-
"win32"
970-
],
971-
"parameters": [
972-
"webDriverBiDi"
973-
],
974-
"expectations": [
975-
"FAIL"
976-
]
977-
},
978963
{
979964
"comment": "This is part of organizing the webdriver bidi implementation, We will remove it one by one",
980965
"testIdPattern": "[page.spec] *Page.Events.Console*",

lib/PuppeteerSharp/Bidi/BidiPage.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,5 +583,9 @@ await BidiMainFrame.Client.SendAsync(
583583

584584
private void Initialize()
585585
{
586+
BidiMainFrame.BrowsingContext.Closed += (_, _) =>
587+
{
588+
OnClose();
589+
};
586590
}
587591
}

lib/PuppeteerSharp/Bidi/Core/BrowsingContext.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private BrowsingContext(UserContext userContext, BrowsingContext parent, string
7171

7272
public string Url { get; private set; }
7373

74-
public bool IsClosed => _reason != null;
74+
public bool IsClosed { get; private set; }
7575

7676
public Session Session => UserContext.Browser.Session;
7777

@@ -107,6 +107,13 @@ public static BrowsingContext From(UserContext userContext, BrowsingContext pare
107107

108108
public void Dispose()
109109
{
110+
if (IsClosed)
111+
{
112+
return;
113+
}
114+
115+
IsClosed = true;
116+
110117
_reason ??= "Browser was disconnected, probably because the session ended.";
111118
OnClosed(_reason);
112119
foreach (var context in _children.Values)
@@ -223,7 +230,7 @@ private void Initialize()
223230

224231
Session.BrowsingContextContextDestroyed += (_, args) =>
225232
{
226-
if (args.UserContextId != Id)
233+
if (args.BrowsingContextId != Id)
227234
{
228235
return;
229236
}

0 commit comments

Comments
 (0)