Skip to content

Commit d98f9c6

Browse files
authored
Multi-platform support (#98)
1 parent 904e7e7 commit d98f9c6

File tree

7 files changed

+31
-15
lines changed

7 files changed

+31
-15
lines changed

lib/PuppeteerSharp.Tests/PuppeteerLoaderFixture.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ private async Task StartWebServerAsync()
5858
"PuppeteerSharp.TestServer");
5959

6060
_webServerProcess = new Process();
61+
_webServerProcess.StartInfo.UseShellExecute = false;
6162
_webServerProcess.StartInfo.FileName = "dotnet";
6263
_webServerProcess.StartInfo.WorkingDirectory = webServerPath;
6364
_webServerProcess.StartInfo.Arguments = $"./bin/{build}/netcoreapp2.0/PuppeteerSharp.TestServer.dll";

lib/PuppeteerSharp.Tests/PuppeteerSharp.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.0</TargetFramework>
5-
4+
<TargetFrameworks>netcoreapp2.0;net471</TargetFrameworks>
65
<IsPackable>false</IsPackable>
76
</PropertyGroup>
87

98
<ItemGroup>
9+
<PackageReference Include="Microsoft.CSharp" Version="4.4.1" />
1010
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170628-02" />
1111
<PackageReference Include="xunit" Version="2.2.0" />
1212
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />

lib/PuppeteerSharp/Connection.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public Connection(string url, int delay, ClientWebSocket ws)
1818
Delay = delay;
1919
WebSocket = ws;
2020

21+
_socketQueue = new TaskQueue();
2122
_responses = new Dictionary<int, TaskCompletionSource<dynamic>>();
2223
_sessions = new Dictionary<string, Session>();
2324
_connectionCloseTask = new TaskCompletionSource<bool>();
@@ -36,6 +37,7 @@ public Connection(string url, int delay, ClientWebSocket ws)
3637

3738
private bool _closeMessageSent;
3839
private const string CloseMessage = "Browser.close";
40+
private TaskQueue _socketQueue;
3941
#endregion
4042

4143
#region Properties
@@ -62,7 +64,8 @@ public async Task<dynamic> SendAsync(string method, dynamic args = null)
6264
var encoded = Encoding.UTF8.GetBytes(message);
6365
var buffer = new ArraySegment<Byte>(encoded, 0, encoded.Length);
6466
QueueId(id);
65-
await WebSocket.SendAsync(buffer, WebSocketMessageType.Text, true, default(CancellationToken));
67+
68+
await _socketQueue.Enqueue(() => WebSocket.SendAsync(buffer, WebSocketMessageType.Text, true, default(CancellationToken)));
6669

6770
//I don't know if this will be the final solution.
6871
//For now this will prevent the WebSocket from failing after the process is killed by the close method.

lib/PuppeteerSharp/Helpers/ProcessExtensions.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,21 @@ public static class ProcessExtensions
99
{
1010
public static void RemoveExitedEvent(this Process process)
1111
{
12-
var eventField = typeof(Process).GetField("_onExited", BindingFlags.NonPublic | BindingFlags.Instance);
13-
object obj = eventField.GetValue(process);
14-
PropertyInfo pi = process.GetType().GetProperty("Events", BindingFlags.NonPublic | BindingFlags.Instance);
15-
EventHandlerList list = (EventHandlerList)pi.GetValue(process, null);
16-
list.RemoveHandler(obj, list[obj]);
12+
RemoveHandler(process, "_onExited");
13+
RemoveHandler(process, "onExited");
14+
}
15+
16+
private static void RemoveHandler(Process process, string fieldId)
17+
{
18+
var eventField = typeof(Process).GetField(fieldId, BindingFlags.NonPublic | BindingFlags.Instance);
19+
20+
if (eventField != null)
21+
{
22+
object obj = eventField.GetValue(process);
23+
var pi = process.GetType().GetProperty("Events", BindingFlags.NonPublic | BindingFlags.Instance);
24+
var list = (EventHandlerList)pi.GetValue(process, null);
25+
list.RemoveHandler(obj, list[obj]);
26+
}
1727
}
1828
}
1929
}

lib/PuppeteerSharp/Launcher.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public async Task<Browser> LaunchAsync(LaunchOptions options, int chromiumRevisi
129129

130130
_chromeProcess = new Process();
131131
_chromeProcess.EnableRaisingEvents = true;
132+
_chromeProcess.StartInfo.UseShellExecute = false;
132133
_chromeProcess.StartInfo.FileName = chromeExecutable;
133134
_chromeProcess.StartInfo.Arguments = string.Join(" ", chromeArguments);
134135

lib/PuppeteerSharp/PuppeteerSharp.csproj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<PackOnBuild>true</PackOnBuild>
6-
<PackageVersion>0.3.0</PackageVersion>
6+
<PackageVersion>0.3.1</PackageVersion>
77
<Authors>Darío Kondratiuk</Authors>
88
<Owners>Darío Kondratiuk</Owners>
99
<PackageProjectUrl>https://github.com/kblok/puppeteer-sharp</PackageProjectUrl>
@@ -12,9 +12,10 @@
1212
<Title>PuppeteerSharp</Title>
1313
<Description>Headless Chrome .NET API</Description>
1414
<PackageId>PuppeteerSharp</PackageId>
15-
<PackageReleaseNotes>* 0.3: Process improvements, User data dir support
16-
* 0.1: PDF and Screenshots support</PackageReleaseNotes>
17-
<ReleaseVersion>0.3</ReleaseVersion>
15+
<PackageReleaseNotes>* 0.3.1 : .NET Framework Support
16+
* 0.3.0 : Process improvements, User data dir support
17+
* 0.1.0 : PDF and Screenshots support</PackageReleaseNotes>
18+
<ReleaseVersion>0.3.1</ReleaseVersion>
1819
<SynchReleaseVersion>false</SynchReleaseVersion>
1920
</PropertyGroup>
2021
<ItemGroup>

lib/PuppeteerSharp/Session.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public Session(Connection connection, string targetId, string sessionId)
2626
#endregion
2727

2828
#region Properties
29-
public string TargetId { get; private set; }
29+
public string TargetId { get; }
3030
public string SessionId { get; private set; }
3131
public Connection Connection { get; private set; }
3232
public event EventHandler<MessageEventArgs> MessageReceived;
@@ -40,9 +40,9 @@ public async Task<T> SendAsync<T>(string method, dynamic args = null)
4040
return JsonConvert.DeserializeObject<T>(content);
4141
}
4242

43-
public async Task<dynamic> SendAsync(string method, dynamic args = null)
43+
public Task<dynamic> SendAsync(string method, dynamic args = null)
4444
{
45-
return await SendAsync(method, false, args);
45+
return SendAsync(method, false, args);
4646
}
4747

4848
public async Task<dynamic> SendAsync(string method, bool rawContent, dynamic args = null)

0 commit comments

Comments
 (0)