Skip to content

Commit 2dc3661

Browse files
authored
Option for WebSocket keepAliveInterval (#63)
1 parent 64f440a commit 2dc3661

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

lib/PuppeteerSharp.Tests/TestConstants.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public static class TestConstants
1515
{ "slowMo", Convert.ToInt32(Environment.GetEnvironmentVariable("SLOW_MO") ?? "0") },
1616
{ "headless", Convert.ToBoolean(Environment.GetEnvironmentVariable("HEADLESS") ?? "true") },
1717
{ "args", new[] { "--no-sandbox" }},
18-
{ "timeout", 0}
18+
{ "timeout", 0},
19+
{ "keepAliveInterval", 120}
1920
};
2021
}
2122
}

lib/PuppeteerSharp/Connection.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,10 @@ await Task.WhenAny(
190190
#endregion
191191
#region Static Methods
192192

193-
public static async Task<Connection> Create(string url, int delay = 0)
193+
public static async Task<Connection> Create(string url, int delay = 0, int keepAliveInterval = 60)
194194
{
195195
var ws = new ClientWebSocket();
196+
ws.Options.KeepAliveInterval = new TimeSpan(0, 0, keepAliveInterval);
196197
await ws.ConnectAsync(new Uri(url), default(CancellationToken)).ConfigureAwait(false);
197198
return new Connection(url, delay, ws);
198199
}

lib/PuppeteerSharp/Launcher.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@ internal async Task<Browser> LaunchAsync(Dictionary<string, object> options, int
125125
var browserWSEndpoint = await WaitForEndpoint(_chromeProcess,
126126
(int)(options.GetValueOrDefault("timeout") ?? 30 * 100),
127127
options.ContainsKey("dumpio"));
128+
var keepAliveInterval = options.ContainsKey("keepAliveInterval") ? Convert.ToInt32(options["keepAliveInterval"]) : 30;
128129

129-
_connection = await Connection.Create(browserWSEndpoint, connectionDelay);
130+
_connection = await Connection.Create(browserWSEndpoint, connectionDelay, keepAliveInterval);
130131
return await Browser.CreateAsync(_connection, options, KillChrome);
131132
}
132133
catch (Exception ex)

0 commit comments

Comments
 (0)