Exempt the Electron desktop shell from loading Admiral ads (#4651)

**Add approved & assigned issue number here:**

## Description:

Admiral (`src/client/Admiral.ts`), OpenFront's ad-recovery vendor, is
injected via a runtime `document.createElement("script")` call rather
than a static HTML `<script>` tag. That makes it invisible to HTML-level
ad stripping done in the (private, separate) Electron/Steam shell repo,
so it was attempting to load — and cascading into further ad-exchange
calls — inside the paid desktop client.

`Main.ts` already exempts CrazyGames-hosted sessions from Admiral via
`window.adsEnabled = !isAdFree && !crazyGamesSDK.isOnCrazyGames()`. This
extends that same, existing gate to also cover the Electron desktop
shell, detected via a new `src/client/DesktopShell.ts`
(`isDesktopShell()`), which mirrors `CrazyGamesSDK.ts`'s
`isOnCrazyGames()` pattern: it checks for `window.openfrontDesktop`, a
global only the Electron app's own preload script ever sets. No behavior
change for web/CrazyGames users — the change is a single additional `&&`
clause.

## Please complete the following:

- [x] I have added screenshots for all UI updates — n/a, no UI change
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file — n/a, no user-facing text added
- [ ] I have added relevant tests to the test directory — no unit test
added; following existing convention in this area (`CrazyGamesSDK.ts`'s
`isOnCrazyGames()`, the pattern this mirrors, also has no dedicated unit
test). Verified instead via `tsc --noEmit`, `eslint`/`prettier`, a full
`build-prod`, and the Electron shell's own e2e network-isolation test
confirming Admiral's script (and downstream ad-exchange calls) no longer
attempt to load when `window.openfrontDesktop` is present.

## Please put your Discord username so you can be contacted if a bug or
regression is found:

jish
This commit is contained in:
Josh Harris
2026-07-22 13:08:04 -07:00
committed by GitHub
parent ebd22af95e
commit 3e2251bbbb
2 changed files with 16 additions and 1 deletions
+13
View File
@@ -0,0 +1,13 @@
// The Electron desktop (Steam) shell exposes this global via a contextBridge
// preload script — see openfront-desktop's src/preload/preload.ts. Its mere
// presence is a reliable signal we're running inside that shell, since only
// the desktop build's preload script ever sets it.
declare global {
interface Window {
openfrontDesktop?: unknown;
}
}
export function isDesktopShell(): boolean {
return typeof window !== "undefined" && window.openfrontDesktop !== undefined;
}
+3 -1
View File
@@ -26,6 +26,7 @@ import "./CosmeticsModal";
import { CosmeticsModal } from "./CosmeticsModal";
import { updateCrazyGamesNavButton } from "./CrazyGamesAccountButton";
import { crazyGamesSDK } from "./CrazyGamesSDK";
import { isDesktopShell } from "./DesktopShell";
import "./FeaturedStream";
import "./FlagInput";
import { FlagInput } from "./FlagInput";
@@ -505,7 +506,8 @@ class Client {
}
const isAdFree =
userMeResponse !== false && userMeResponse.player?.adfree === true;
window.adsEnabled = !isAdFree && !crazyGamesSDK.isOnCrazyGames();
window.adsEnabled =
!isAdFree && !crazyGamesSDK.isOnCrazyGames() && !isDesktopShell();
// Ad-eligible users only: paid/adfree users must never load Admiral (its
// adblock popup fires autonomously once the payload runs). Start watching
// adblock state; once a blocker is ever detected the in-game ad is