Skip to content

Commit

Permalink
Small improvements for CloudFlare support
Browse files Browse the repository at this point in the history
  • Loading branch information
leMicin committed Jan 12, 2025
1 parent 3c30d3d commit 1daee9f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Sidekick.Apis.Poe/Clients/PoeTradeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class PoeTradeHandler
IGameLanguageProvider gameLanguageProvider
) : DelegatingHandler
{
public const string UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36";
public const string UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0";

protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
Expand Down
5 changes: 5 additions & 0 deletions src/Sidekick.Wpf/CloudflareWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel;
using System.Net;
using System.Windows;
using System.Windows.Media;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -36,6 +37,7 @@ public void Ready()

await WebView.EnsureCoreWebView2Async();
WebView.CoreWebView2.Settings.UserAgent = PoeTradeHandler.UserAgent;
WebView.CoreWebView2.CookieManager.DeleteAllCookies();

// Handle cookie changes by checking cookies after navigation
WebView.CoreWebView2.NavigationCompleted += CoreWebView2_NavigationCompleted;
Expand Down Expand Up @@ -72,10 +74,13 @@ private async void CoreWebView2_NavigationCompleted(object? sender, CoreWebView2
{
try
{
logger.LogInformation("[CloudflareWindow] Checking for Cloudflare cookie at " + WebUtility.UrlDecode(WebView.Source?.ToString()));

var cookies = await WebView.CoreWebView2.CookieManager.GetCookiesAsync(uri.GetLeftPart(UriPartial.Authority));
var cfCookie = cookies.FirstOrDefault(c => c.Name == "cf_clearance");
if (cfCookie == null)
{
logger.LogInformation("[CloudflareWindow] Cookie not found");
return;
}

Expand Down

0 comments on commit 1daee9f

Please sign in to comment.