diff --git a/README.md b/README.md index 938f2365..22120248 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ | | Linux | macOS | Windows | | :--- | :---: | :---: | :---: | -| Chromium 120.0.6099.28 | ✅ | ✅ | ✅ | +| Chromium 120.0.6099.56 | ✅ | ✅ | ✅ | | WebKit 17.4 | ✅ | ✅ | ✅ | | Firefox 119.0 | ✅ | ✅ | ✅ | diff --git a/build.sh b/build.sh index 679c6bdb..d7caa795 100755 --- a/build.sh +++ b/build.sh @@ -51,9 +51,6 @@ function update_assets() { } function roll_driver() { - cat "${upstream_repo_path}/utils/build/run-driver-posix.sh" | sed "s|package|../../package|" > "src/Playwright/Scripts/playwright.sh" - cat "${upstream_repo_path}/utils/build/run-driver-win.cmd" | sed "s|package|..\\\..\\\package|" > "src/Playwright/Scripts/playwright.cmd" - new_driver_version="$1" upstream_package_version=$(node -e "console.log(require('${upstream_repo_path}/package.json').version)") echo "Rolling .NET driver to driver ${new_driver_version} and upstream version ${upstream_package_version}..." diff --git a/src/Playwright.Tests/BrowserTypeConnectTests.cs b/src/Playwright.Tests/BrowserTypeConnectTests.cs index ad1ff337..badc6ade 100644 --- a/src/Playwright.Tests/BrowserTypeConnectTests.cs +++ b/src/Playwright.Tests/BrowserTypeConnectTests.cs @@ -520,7 +520,8 @@ public class BrowserTypeConnectTests : PlaywrightTestEx { try { - var startInfo = new ProcessStartInfo(Driver.GetExecutablePath(), $"launch-server --browser {browserName}") + var (executablePath, getArgs) = Driver.GetExecutablePath(); + var startInfo = new ProcessStartInfo(executablePath, getArgs($"launch-server --browser {browserName}")) { UseShellExecute = false, RedirectStandardOutput = true, diff --git a/src/Playwright/Helpers/Driver.cs b/src/Playwright/Helpers/Driver.cs index 079ff873..1e5486d8 100644 --- a/src/Playwright/Helpers/Driver.cs +++ b/src/Playwright/Helpers/Driver.cs @@ -39,7 +39,7 @@ internal static class Driver ["PW_CLI_DISPLAY_VERSION"] = typeof(Driver).Assembly.GetName().Version.ToString(3), }; - internal static string GetExecutablePath() + internal static (string ExecutablePath, Func GetArgs) GetExecutablePath() { DirectoryInfo assemblyDirectory = null; if (!string.IsNullOrEmpty(AppContext.BaseDirectory)) @@ -64,53 +64,54 @@ internal static class Driver } string executableFile; + Func getArgs; // When loading the Assembly via the memory we don't have any references where the driver might be located. // To workaround this we pass this env from the .ps1 wrapper over to the Assembly. var driverSearchPath = Environment.GetEnvironmentVariable("PLAYWRIGHT_DRIVER_SEARCH_PATH"); if (!string.IsNullOrEmpty(driverSearchPath)) { - executableFile = GetPath(driverSearchPath); + (executableFile, getArgs) = GetPath(driverSearchPath); if (!File.Exists(executableFile)) { throw new PlaywrightException("Couldn't find driver in \"PLAYWRIGHT_DRIVER_SEARCH_PATH\""); } - return executableFile; + return (executableFile, getArgs); } - executableFile = GetPath(assemblyDirectory.FullName); + (executableFile, getArgs) = GetPath(assemblyDirectory.FullName); if (File.Exists(executableFile)) { - return executableFile; + return (executableFile, getArgs); } // if the above fails, we can assume we're in the nuget registry - executableFile = GetPath(assemblyDirectory.Parent.Parent.FullName); + (executableFile, getArgs) = GetPath(assemblyDirectory.Parent.Parent.FullName); if (File.Exists(executableFile)) { - return executableFile; + return (executableFile, getArgs); } throw new PlaywrightException($"Driver not found: {executableFile}"); } - private static string GetPath(string driversPath) + private static (string ExecutablePath, Func GetArgs) GetPath(string driversPath) { string platformId; - string runnerName; + string nodeExecutable; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { platformId = "win32_x64"; - runnerName = "playwright.cmd"; + nodeExecutable = "node.exe"; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { - runnerName = "playwright.sh"; + nodeExecutable = "node"; platformId = RuntimeInformation.ProcessArchitecture == Architecture.Arm64 ? "darwin-arm64" : "darwin-x64"; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { - runnerName = "playwright.sh"; + nodeExecutable = "node"; platformId = RuntimeInformation.ProcessArchitecture == Architecture.Arm64 ? "linux-arm64" : "linux-x64"; } else @@ -118,6 +119,13 @@ internal static class Driver throw new PlaywrightException("Unknown platform"); } - return Path.Combine(driversPath, ".playwright", "node", platformId, runnerName); + var cliEntrypoint = Path.Combine(driversPath, ".playwright", "package", "lib", "cli", "cli.js"); + string getArgs(string args) + { + return !string.IsNullOrEmpty(args) ? $"\"{cliEntrypoint}\" {args}" : cliEntrypoint; + } + return ( + Environment.GetEnvironmentVariable("PLAYWRIGHT_NODEJS_PATH") ?? Path.GetFullPath(Path.Combine(driversPath, ".playwright", "node", platformId, nodeExecutable)), + getArgs); } } diff --git a/src/Playwright/Playwright.csproj b/src/Playwright/Playwright.csproj index ad4b3246..224b956d 100644 --- a/src/Playwright/Playwright.csproj +++ b/src/Playwright/Playwright.csproj @@ -43,11 +43,6 @@ - - - - - diff --git a/src/Playwright/Program.cs b/src/Playwright/Program.cs index 53ced41f..bc5a8e48 100644 --- a/src/Playwright/Program.cs +++ b/src/Playwright/Program.cs @@ -38,18 +38,18 @@ public class Program public int Run(string[] args) { - string pwPath = null; + Func getArgs; + string executablePath; try { - pwPath = Driver.GetExecutablePath(); + (executablePath, getArgs) = Driver.GetExecutablePath(); } catch { return PrintError("Microsoft.Playwright assembly was found, but is missing required assets. Please ensure to build your project before running Playwright tool."); } - string allArgs = args != null && args.Length > 0 ? "\"" + string.Join("\" \"", args) + "\"" : string.Empty; - var playwrightStartInfo = new ProcessStartInfo(pwPath, allArgs) + var playwrightStartInfo = new ProcessStartInfo(executablePath, getArgs(args?.Length > 0 ? "\"" + string.Join("\" \"", args) + "\"" : null)) { UseShellExecute = false, // This works after net8.0-preview-4 diff --git a/src/Playwright/Scripts/playwright.cmd b/src/Playwright/Scripts/playwright.cmd deleted file mode 100755 index 3485577a..00000000 --- a/src/Playwright/Scripts/playwright.cmd +++ /dev/null @@ -1,4 +0,0 @@ -@echo off -setlocal -if not defined PLAYWRIGHT_NODEJS_PATH set PLAYWRIGHT_NODEJS_PATH=%~dp0node.exe -"%PLAYWRIGHT_NODEJS_PATH%" "%~dp0..\..\package\lib\cli\cli.js" %* \ No newline at end of file diff --git a/src/Playwright/Scripts/playwright.sh b/src/Playwright/Scripts/playwright.sh deleted file mode 100755 index 8e0c1c00..00000000 --- a/src/Playwright/Scripts/playwright.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -SCRIPT_PATH="$(cd "$(dirname "$0")" ; pwd -P)" -if [ -z "$PLAYWRIGHT_NODEJS_PATH" ]; then - PLAYWRIGHT_NODEJS_PATH="$SCRIPT_PATH/node" -fi -"$PLAYWRIGHT_NODEJS_PATH" "$SCRIPT_PATH/../../package/lib/cli/cli.js" "$@" diff --git a/src/Playwright/Transport/StdIOTransport.cs b/src/Playwright/Transport/StdIOTransport.cs index 50b248a8..da52ffac 100644 --- a/src/Playwright/Transport/StdIOTransport.cs +++ b/src/Playwright/Transport/StdIOTransport.cs @@ -43,8 +43,7 @@ internal class StdIOTransport : IDisposable internal StdIOTransport() { - _process = GetProcess(); - _process.StartInfo.Arguments = "run-driver"; + _process = GetProcess("run-driver"); StartProcessWithUTF8IOEncoding(_process); _process.Exited += (_, _) => Close(new TargetClosedException("Process exited")); _process.ErrorDataReceived += (_, error) => @@ -112,9 +111,10 @@ internal class StdIOTransport : IDisposable } } - private static Process GetProcess() + private static Process GetProcess(string driverArgs) { - var startInfo = new ProcessStartInfo(Driver.GetExecutablePath()) + var (executablePath, getArgs) = Driver.GetExecutablePath(); + var startInfo = new ProcessStartInfo(executablePath, getArgs(driverArgs)) { UseShellExecute = false, RedirectStandardOutput = true, diff --git a/src/Playwright/build/Microsoft.Playwright.targets b/src/Playwright/build/Microsoft.Playwright.targets index d497675d..8e669161 100644 --- a/src/Playwright/build/Microsoft.Playwright.targets +++ b/src/Playwright/build/Microsoft.Playwright.targets @@ -57,10 +57,10 @@ - + - <_PlaywrightChmodItems Include="$(OutputPath).playwright\node\*\playwright.sh" /> - <_PlaywrightChmodItems Include="$(PublishDir).playwright\node\*\playwright.sh" /> + <_PlaywrightChmodItems Include="$(OutputPath).playwright\node\*\node" /> + <_PlaywrightChmodItems Include="$(PublishDir).playwright\node\*\node" /> diff --git a/src/tools/Playwright.Tooling/DriverDownloader.cs b/src/tools/Playwright.Tooling/DriverDownloader.cs index b43c4670..a6cf4a69 100644 --- a/src/tools/Playwright.Tooling/DriverDownloader.cs +++ b/src/tools/Playwright.Tooling/DriverDownloader.cs @@ -26,13 +26,10 @@ using System; using System.Collections.Generic; using System.IO; using System.IO.Compression; -using System.Linq; using System.Net.Http; -using System.Runtime.InteropServices; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Xml; -using DriverDownloader.Linux; using Playwright.Tooling.Options; namespace Playwright.Tooling; @@ -137,20 +134,6 @@ internal class DriverDownloader new ZipArchive(await response.Content.ReadAsStreamAsync().ConfigureAwait(false)).ExtractToDirectory(directory.FullName); - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - var executables = new[] { "playwright.sh", "node" } - .Select(f => Path.Combine(directory.FullName, f)); - - foreach (string executable in executables) - { - if (new FileInfo(executable).Exists && LinuxSysCall.Chmod(executable, LinuxSysCall.ExecutableFilePermissions) != 0) - { - throw new($"Unable to chmod {executable} ({Marshal.GetLastWin32Error()})"); - } - } - } - Console.WriteLine($"Driver for {platform} downloaded"); } catch (Exception ex) diff --git a/src/tools/Playwright.Tooling/Linux/FileAccessPermissions.cs b/src/tools/Playwright.Tooling/Linux/FileAccessPermissions.cs deleted file mode 100644 index 5bac6636..00000000 --- a/src/tools/Playwright.Tooling/Linux/FileAccessPermissions.cs +++ /dev/null @@ -1,44 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2020 Darío Kondratiuk - * Modifications copyright (c) Microsoft Corporation. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -using System; - -namespace DriverDownloader.Linux; - -[Flags] -internal enum FileAccessPermissions : uint -{ - OtherExecute = 1, - OtherWrite = 2, - OtherRead = 4, - - GroupExecute = 8, - GroupWrite = 16, - GroupRead = 32, - - UserExecute = 64, - UserWrite = 128, - UserRead = 256, -} diff --git a/src/tools/Playwright.Tooling/Linux/LinuxSysCall.cs b/src/tools/Playwright.Tooling/Linux/LinuxSysCall.cs deleted file mode 100644 index f64a3916..00000000 --- a/src/tools/Playwright.Tooling/Linux/LinuxSysCall.cs +++ /dev/null @@ -1,43 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2020 Darío Kondratiuk - * Modifications copyright (c) Microsoft Corporation. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -using System.Runtime.InteropServices; - -namespace DriverDownloader.Linux; - -internal static class LinuxSysCall -{ - internal const FileAccessPermissions ExecutableFilePermissions = - FileAccessPermissions.UserRead | - FileAccessPermissions.UserWrite | - FileAccessPermissions.UserExecute | - FileAccessPermissions.GroupRead | - FileAccessPermissions.GroupExecute | - FileAccessPermissions.OtherRead | - FileAccessPermissions.OtherExecute; - - [DllImport("libc", SetLastError = true, EntryPoint = "chmod")] - internal static extern int Chmod(string path, FileAccessPermissions mode); -}