Skip to content

Commit f1a0bce

Browse files
committed
Workaround initial webkit injection issue
Steam has recently introduced a problem where webkit pages (e.g. the store or community tabs) can't access the steam loopback on first load. To workaround this we force a reload on initial injection.
1 parent 125424e commit f1a0bce

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

SFP/Models/Injection/Injector.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public static partial class Injector
1717
private static IBrowser? s_browser;
1818
private static bool s_manualDisconnect;
1919
private static readonly SemaphoreSlim Semaphore = new(1, 1);
20+
private static bool s_webkitReloaded;
2021
public static bool IsInjected { get => field && s_browser != null; private set; }
2122

2223
public static event EventHandler? InjectionStateChanged;
@@ -73,6 +74,7 @@ public static async Task StartInjectionAsync(bool noError = false)
7374
};
7475

7576
Log.Logger.Info("Connecting to " + browserEndpoint);
77+
s_webkitReloaded = false;
7678
s_browser = await Puppeteer.ConnectAsync(options);
7779
s_browser.Disconnected += OnDisconnected;
7880
Log.Logger.Info("Connected");
@@ -126,6 +128,7 @@ public static void StopInjection()
126128
s_manualDisconnect = true;
127129
s_browser?.Disconnect();
128130
s_browser = null;
131+
s_webkitReloaded = false;
129132
InjectionStateChanged?.Invoke(null, EventArgs.Empty);
130133
}
131134

@@ -434,6 +437,9 @@ private static async Task InjectResourceAsync(IFrame frame, string fileRelativeP
434437
var injectString =
435438
$$"""
436439
function inject() {
440+
if ('{{IsFrameWebkit(frame)}}' === 'True' && '{{s_webkitReloaded}}' === 'False') {
441+
location.reload();
442+
}
437443
if (document.getElementById('{{frame.Id}}{{resourceType}}') !== null) return;
438444
const element = document.createElement('{{(resourceType == "css" ? "link" : "script")}}');
439445
element.id = '{{frame.Id}}{{resourceType}}';
@@ -447,14 +453,18 @@ function inject() {
447453
} else {
448454
inject();
449455
}
450-
451456
""";
452457
try
453458
{
454459
if (!IsFrameWebkit(frame) && resourceType == "js")
455460
{
456461
await Task.Delay(500);
457462
}
463+
464+
if (!s_webkitReloaded && IsFrameWebkit(frame))
465+
{
466+
s_webkitReloaded = true;
467+
}
458468
await frame.EvaluateExpressionAsync(injectString);
459469
Log.Logger.Info($"Injected {Path.GetFileName(fileRelativePath)} into {tabFriendlyName} from patch {patchName}");
460470
}

SFP/packages.lock.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,4 +320,4 @@
320320
}
321321
}
322322
}
323-
}
323+
}

0 commit comments

Comments
 (0)