Skip to content

Commit 7bed981

Browse files
authored
Bidi: Implement default context (#2995)
* Bidi: Implement default context * fix
1 parent 7c15500 commit 7bed981

File tree

7 files changed

+13
-21
lines changed

7 files changed

+13
-21
lines changed

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -330,21 +330,6 @@
330330
"FAIL"
331331
]
332332
},
333-
{
334-
"comment": "This is part of organizing the webdriver bidi implementation, We will remove it one by one",
335-
"testIdPattern": "[defaultbrowsercontext.spec] *",
336-
"platforms": [
337-
"darwin",
338-
"linux",
339-
"win32"
340-
],
341-
"parameters": [
342-
"webDriverBiDi"
343-
],
344-
"expectations": [
345-
"FAIL"
346-
]
347-
},
348333
{
349334
"comment": "This is part of organizing the webdriver bidi implementation, We will remove it one by one",
350335
"testIdPattern": "[browsercontext.spec] *",

lib/PuppeteerSharp.Tests/BrowserContextTests/DefaultBrowserContextTests.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ namespace PuppeteerSharp.Tests.BrowserContextTests
77
{
88
public class DefaultBrowserContextTests : PuppeteerPageBaseTest
99
{
10-
public DefaultBrowserContextTests() : base()
11-
{
12-
}
13-
1410
[SetUp]
1511
public async Task CreateNewPageAsync()
1612
{

lib/PuppeteerSharp/Bidi/BidiBrowser.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ private BidiBrowser(Core.Browser browserCore, LaunchOptions options, ILoggerFact
5858
/// <inheritdoc />
5959
public override ITarget Target => _target;
6060

61+
/// <inheritdoc/>
62+
public override IBrowserContext DefaultContext => _browserContexts.FirstOrDefault(b => b.Id == BrowserCore.DefaultUserContext.Id);
63+
6164
internal static string[] SubscribeModules { get; } =
6265
[
6366
"browsingContext",

lib/PuppeteerSharp/Bidi/BidiBrowserContext.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ internal static BidiBrowserContext From(
9999
UserContext userContext,
100100
BidiBrowserContextOptions options)
101101
{
102-
var context = new BidiBrowserContext(browser, userContext, options);
102+
var context = new BidiBrowserContext(browser, userContext, options)
103+
{
104+
Id = userContext.Id,
105+
};
103106
context.Initialize();
104107
return context;
105108
}

lib/PuppeteerSharp/Bidi/Core/Browser.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
using System;
2424
using System.Collections.Concurrent;
2525
using System.Collections.Generic;
26+
using System.Linq;
2627
using System.Threading.Tasks;
2728
using PuppeteerSharp.Helpers;
2829
using WebDriverBiDi.Browser;
@@ -49,6 +50,8 @@ internal sealed class Browser(Session session) : IDisposable
4950

5051
public string Reason { get; set; }
5152

53+
internal UserContext DefaultUserContext => _userContexts.TryGetValue(UserContext.DEFAULT, out var context) ? context : _userContexts.Values.FirstOrDefault();
54+
5255
internal ICollection<UserContext> UserContexts => _userContexts.Values;
5356

5457
public static async Task<Browser> From(Session session)

lib/PuppeteerSharp/Bidi/Core/UserContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ namespace PuppeteerSharp.Bidi.Core;
3030

3131
internal class UserContext : IDisposable
3232
{
33+
public const string DEFAULT = "default";
34+
3335
private readonly ConcurrentDictionary<string, BrowsingContext> _browsingContexts = new();
3436
private string _reason;
3537

lib/PuppeteerSharp/Browser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public abstract class Browser : IBrowser
4747
public abstract bool IsClosed { get; }
4848

4949
/// <inheritdoc/>
50-
public IBrowserContext DefaultContext { get; protected set; }
50+
public virtual IBrowserContext DefaultContext { get; protected set; }
5151

5252
/// <inheritdoc/>
5353
public int DefaultWaitForTimeout { get; set; } = Puppeteer.DefaultTimeout;

0 commit comments

Comments
 (0)