Skip to content

Commit

Permalink
Roll chrome to 125 (#2637)
Browse files Browse the repository at this point in the history
* Roll chrome to 125

* Try set windows permissions

* improve code

* Fix style

* test new command

* Update lib/PuppeteerSharp/BrowserFetcher.cs

* use new version

* Maybe it just need more time?
  • Loading branch information
kblok committed May 23, 2024
1 parent 5d6c91c commit 1b22369
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,31 @@ public async Task ShouldWork()
public async Task ShouldWorkWithBothDomcontentloadedAndLoad()
{
var responseCompleted = new TaskCompletionSource<bool>();
Server.SetRoute("/one-style.css", _ =>
{
return responseCompleted.Task;
});
Server.SetRoute("/one-style.css", _ => responseCompleted.Task);

var waitForRequestTask = Server.WaitForRequest("/one-style.css");
var navigationTask = Page.GoToAsync(TestConstants.ServerUrl + "/one-style.html");
var domContentLoadedTask = Page.WaitForNavigationAsync(new NavigationOptions
{
WaitUntil = new[] { WaitUntilNavigation.DOMContentLoaded }
WaitUntil = [WaitUntilNavigation.DOMContentLoaded]
});

var bothFired = false;
var bothFiredTask = Page.WaitForNavigationAsync(new NavigationOptions
{
WaitUntil = new[]
{
WaitUntil =
[
WaitUntilNavigation.Load,
WaitUntilNavigation.DOMContentLoaded
}
]
}).ContinueWith(_ => bothFired = true);

await waitForRequestTask.WithTimeout();
await domContentLoadedTask.WithTimeout();
await waitForRequestTask.WithTimeout(5_000);
await domContentLoadedTask.WithTimeout(5_000);
Assert.False(bothFired);
responseCompleted.SetResult(true);
await bothFiredTask.WithTimeout();
await navigationTask.WithTimeout();
await bothFiredTask.WithTimeout(5_000);
await navigationTask.WithTimeout(5_000);
}

[Test, Retry(2), PuppeteerTest("navigation.spec", "navigation Page.waitForNavigation", "should work with clicking on anchor links")]
Expand Down
4 changes: 3 additions & 1 deletion lib/PuppeteerSharp/BrowserData/Chrome.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public static class Chrome
/// <summary>
/// Default chrome build.
/// </summary>
public static string DefaultBuildId => "124.0.6367.201";
public static string DefaultBuildId => "125.0.6422.76";

internal static int ChromeVersionRequiringPermissionsFix => 125;

internal static async Task<string> ResolveBuildIdAsync(ChromeReleaseChannel channel)
=> (await GetLastKnownGoodReleaseForChannel(channel).ConfigureAwait(false)).Version;
Expand Down
34 changes: 32 additions & 2 deletions lib/PuppeteerSharp/BrowserFetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ private async Task<InstalledBrowser> DownloadAsync(SupportedBrowser browser, str
throw new PuppeteerException($"Failed to download {browser} for {Platform} from {url}", ex);
}

await UnpackArchiveAsync(archivePath, outputPath, fileName).ConfigureAwait(false);
await UnpackArchiveAsync(archivePath, outputPath, fileName, browser, buildId).ConfigureAwait(false);
new FileInfo(archivePath).Delete();

return new InstalledBrowser(cache, browser, buildId, Platform);
Expand Down Expand Up @@ -357,7 +357,7 @@ private Task<string> ResolveBuildIdAsync(BrowserTag tag)
}
}

private async Task UnpackArchiveAsync(string archivePath, string outputPath, string archiveName)
private async Task UnpackArchiveAsync(string archivePath, string outputPath, string archiveName, SupportedBrowser browser, string buildId)
{
if (archivePath.EndsWith(".zip", StringComparison.OrdinalIgnoreCase))
{
Expand Down Expand Up @@ -405,6 +405,36 @@ private async Task UnpackArchiveAsync(string archivePath, string outputPath, str
}
}
}

if (browser == SupportedBrowser.Chrome && (GetCurrentPlatform() == Platform.Win64 || GetCurrentPlatform() == Platform.Win32))
{
if (int.TryParse(buildId.Split('.').First(), out var majorVersion) &&
majorVersion >= Chrome.ChromeVersionRequiringPermissionsFix)
{
TrySetWindowsPermissions(outputPath);
}
}
}

private void TrySetWindowsPermissions(string outputPath)
{
try
{
var startInfo = new ProcessStartInfo
{
FileName = "icacls.exe",
Arguments = $"\"{outputPath}\" /grant *S-1-15-2-2:(OI)(CI)(RX)",
WindowStyle = ProcessWindowStyle.Hidden,
};
var process = Process.Start(startInfo);
process?.WaitForExit();
}
catch (Exception e)
{
Console.WriteLine("Unable to fix permissions: " + e.Message);
Console.WriteLine($"Visit https://pptr.dev/troubleshooting#chrome-reports-sandbox-errors-on-windows for more information");
throw;
}
}

private async Task DownloadFileUsingHttpClientTaskAsync(string address, string filename)
Expand Down

0 comments on commit 1b22369

Please sign in to comment.