Commit: 4693b9d
Parent: a041ca0

Use Playwright settings from Lukas

Mårten Åsberg committed on 2026-06-04 at 19:19
To circumvent Cloudflare?
BfiScreeningCheckerJob.cs +5 -1
diff --git a/BfiScreeningCheckerJob.cs b/BfiScreeningCheckerJob.cs
index 0a69ffd..883769b 100644
@@ -26,7 +26,11 @@ internal sealed class BfiScreeningCheckerJob(
try
{
logger.LogFetchingSite(opts.Url);
await page.GotoAsync(opts.Url, new() { WaitUntil = WaitUntilState.DOMContentLoaded });
await page.GotoAsync(
opts.Url,
new() { WaitUntil = WaitUntilState.DOMContentLoaded, Timeout = TimeSpan.FromSeconds(45).Milliseconds }
);
await Task.Delay(TimeSpan.FromSeconds(2));
var resultsElement = await page.WaitForSelectorAsync(opts.Selector);
if (resultsElement is null)
{
PlaywrightBrowserService.cs +13 -1
diff --git a/PlaywrightBrowserService.cs b/PlaywrightBrowserService.cs
index 80722fb..eac4bb0 100644
@@ -17,6 +17,9 @@ internal sealed class PlaywrightBrowserService(IOptions<MonitorOptions> options)
Args =
[
"--disable-blink-features=AutomationControlled",
"--no-sandbox",
"--disable-dev-shm-usage",
"--disable-gpu",
// "new" headless mode has a much closer fingerprint to headed Chrome
// than the legacy headless implementation, helping bypass bot detection.
.. options.Value.Headless ? ["--headless=new"] : Array.Empty<string>(),
@@ -29,7 +32,16 @@ internal sealed class PlaywrightBrowserService(IOptions<MonitorOptions> options)
public async Task<IPage> NewPageAsync()
{
var page = await browser!.NewPageAsync();
var ctx = await browser!.NewContextAsync(
new()
{
UserAgent =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
Locale = "en-GB",
ViewportSize = new() { Width = 1280, Height = 720 },
}
);
var page = await ctx.NewPageAsync();
// Patch navigator.webdriver before any page script runs so Cloudflare sees undefined.
await page.AddInitScriptAsync("Object.defineProperty(navigator,'webdriver',{get:()=>undefined})");
return page;