Skip to content

Commit

Permalink
Embedded drivers (#830)
Browse files Browse the repository at this point in the history
* Fix install location

* embedded
  • Loading branch information
kblok authored Sep 6, 2020
1 parent bc5d7d3 commit 2dc5d44
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 25 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Playwright-Sharp

[![NuGetAbstractions](https://buildstats.info/nuget/PlaywrightSharp.Abstractions)][NuGetAbstractions]
[![NuGetChromium](https://buildstats.info/nuget/PlaywrightSharp.Chromium)][NugetChromiumUrl]
[![NuGetAbstractions](https://buildstats.info/nuget/PlaywrightSharp)][NuGet]
[![CodeFactor](https://www.codefactor.io/repository/github/hardkoded/playwright-sharp/badge)][CodeFactorUrl]
[![Join Slack](https://img.shields.io/badge/join-slack-infomational)](https://join.slack.com/t/playwright/shared_invite/enQtOTEyMTUxMzgxMjIwLThjMDUxZmIyNTRiMTJjNjIyMzdmZDA3MTQxZWUwZTFjZjQwNGYxZGM5MzRmNzZlMWI5ZWUyOTkzMjE5Njg1NDg)
[![Backers](https://opencollective.com/hardkoded-projects/backers/badge.svg)][Backers]

[NuGetAbstractions]: https://www.nuget.org/packages/PlaywrightSharp.Abstractions/
[NuGet]: https://www.nuget.org/packages/PlaywrightSharp/
[NugetChromiumUrl]: https://www.nuget.org/packages/PlaywrightSharp.Chromium/
[CodeFactorUrl]: https://www.codefactor.io/repository/github/hardkoded/playwright-sharp
[Backers]: https://opencollective.com/hardkoded-projects
Expand Down
5 changes: 4 additions & 1 deletion demos/PdfDemo/PdfDemo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="PlaywrightSharp.Chromium" Version="0.10.3" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="PlaywrightSharp" Version="0.111.2" />
</ItemGroup>
</Project>
5 changes: 4 additions & 1 deletion demos/ScreenshotsDemo/ScreenshotsDemo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="PlaywrightSharp.Firefox" Version="0.10.3" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="PlaywrightSharp" Version="0.111.2" />
</ItemGroup>
</Project>
6 changes: 3 additions & 3 deletions src/Common/PackageInfo.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<Project>
<PropertyGroup>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>0.111.0</PackageVersion>
<PackageVersion>0.111.2</PackageVersion>
<AssemblyVersion>$(PackageVersion)</AssemblyVersion>
<FileVersion>$(PackageVersion)</FileVersion>
<Authors>Darío Kondratiuk</Authors>
<Owners>Darío Kondratiuk</Owners>
<PackageProjectUrl>https://github.com/hardkoded/playwright-sharp</PackageProjectUrl>
<PackageProjectUrl>https://github.com/hardkodedinstallasy/playwright-sharp</PackageProjectUrl>
<PackageTags>headless,chrome,firefox,webkit,playwright</PackageTags>
<PackageReleaseNotes><![CDATA[
]]></PackageReleaseNotes>
</PropertyGroup>
</Project>
</Project>
24 changes: 12 additions & 12 deletions src/PlaywrightSharp/PlaywrightSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,20 @@
</ItemGroup>
<ItemGroup>
<None Remove="Drivers\driver-linux" />
<Content Include="Drivers\driver-linux">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<EmbeddedResource Include="Drivers\driver-linux">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
<None Remove="Drivers\driver-macos" />
<Content Include="Drivers\driver-macos">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<EmbeddedResource Include="Drivers\driver-macos">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
<None Remove="Drivers\driver-win.exe" />
<Content Include="Drivers\driver-win.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<EmbeddedResource Include="Drivers\driver-win.exe">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
<None Remove="Drivers\browsers.json" />
<Content Include="Drivers\browsers.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<EmbeddedResource Include="Drivers\browsers.json">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
</Project>
44 changes: 39 additions & 5 deletions src/PlaywrightSharp/Transport/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,53 @@ private static Process GetProcess()
private static string GetExecutablePath()
{
// This is not the final solution.
string tempDirectory = Path.Combine(new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).Directory.FullName, "Drivers");
string playwrightServer = "driver-win.exe";
string tempDirectory = new FileInfo(typeof(Playwright).Assembly.Location).Directory.FullName;
string driver = "driver-win.exe";

if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
playwrightServer = "driver-macos";
driver = "driver-macos";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
playwrightServer = "driver-linux";
driver = "driver-linux";
}

return Path.Combine(tempDirectory, playwrightServer);
string file = Path.Combine(tempDirectory, driver);

if (!new FileInfo(file).Exists)
{
ExtractDriver(file, driver);
}

return file;
}

private static void ExtractDriver(string file, string driver)
{
using (var resource = typeof(Playwright).Assembly.GetManifestResourceStream($"PlaywrightSharp.Drivers.browsers.json"))
{
var fileInfo = new FileInfo(Path.Combine(new FileInfo(file).Directory.FullName, "browsers.json"));
if (fileInfo.Exists)
{
fileInfo.Delete();
}

using var fileStream = new FileStream(fileInfo.FullName, FileMode.OpenOrCreate, FileAccess.Write);
resource.CopyTo(fileStream);
}

using (var resource = typeof(Playwright).Assembly.GetManifestResourceStream($"PlaywrightSharp.Drivers.{driver}"))
{
var fileInfo = new FileInfo(file);
if (fileInfo.Exists)
{
fileInfo.Delete();
}

using var fileStream = new FileStream(file, FileMode.OpenOrCreate, FileAccess.Write);
resource.CopyTo(fileStream);
}
}

private void Transport_MessageReceived(object sender, MessageReceivedEventArgs e)
Expand Down

0 comments on commit 2dc5d44

Please sign in to comment.