Skip to content

Commit 64f440a

Browse files
authored
Launcher should not be static (#62)
We need to allow multiples chromium processors running at the same time
1 parent 58b4cf0 commit 64f440a

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

lib/PuppeteerSharp/Launcher.cs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,13 @@ public class Launcher
3636
"--use-mock-keychain"
3737
};
3838

39-
private static bool _chromeClosed;
40-
private static Process _chromeProcess;
41-
private static string _temporaryUserDataDir = null;
42-
private static Connection _connection = null;
43-
private static Timer _timer = null;
39+
private bool _chromeClosed;
40+
private Process _chromeProcess;
41+
private string _temporaryUserDataDir = null;
42+
private Connection _connection = null;
43+
private Timer _timer = null;
4444

45-
public Launcher()
46-
{
47-
}
48-
49-
internal static async Task<Browser> LaunchAsync(Dictionary<string, object> options, int chromiumRevision)
45+
internal async Task<Browser> LaunchAsync(Dictionary<string, object> options, int chromiumRevision)
5046
{
5147
var chromeArguments = new List<string>(_defaultArgs);
5248

@@ -141,7 +137,7 @@ internal static async Task<Browser> LaunchAsync(Dictionary<string, object> optio
141137

142138
}
143139

144-
private static Task<string> WaitForEndpoint(Process chromeProcess, int timeout, bool dumpio)
140+
private Task<string> WaitForEndpoint(Process chromeProcess, int timeout, bool dumpio)
145141
{
146142
var taskWrapper = new TaskCompletionSource<string>();
147143
var output = string.Empty;
@@ -199,14 +195,14 @@ private static Task<string> WaitForEndpoint(Process chromeProcess, int timeout,
199195
return taskWrapper.Task;
200196
}
201197

202-
private static void CleanUp()
198+
private void CleanUp()
203199
{
204200
_timer?.Dispose();
205201
_timer = null;
206202
_chromeProcess?.RemoveExitedEvent();
207203
}
208204

209-
private static async Task KillChrome()
205+
private async Task KillChrome()
210206
{
211207
if (!string.IsNullOrEmpty(_temporaryUserDataDir))
212208
{
@@ -218,7 +214,7 @@ private static async Task KillChrome()
218214
}
219215
}
220216

221-
private static async Task ForceKillChrome()
217+
private async Task ForceKillChrome()
222218
{
223219
if (_chromeProcess.Id != 0 && Process.GetProcessById(_chromeProcess.Id) != null)
224220
{

lib/PuppeteerSharp/Puppeteer.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,9 @@ namespace PuppeteerSharp
66
{
77
public class Puppeteer
88
{
9-
public Puppeteer()
10-
{
11-
}
12-
139
public static async Task<Browser> LaunchAsync(Dictionary<string, object> options, int chromiumRevision)
1410
{
15-
return await Launcher.LaunchAsync(options, chromiumRevision);
11+
return await new Launcher().LaunchAsync(options, chromiumRevision);
1612
}
1713
}
1814
}

0 commit comments

Comments
 (0)