Skip to content

Commit 94e347e

Browse files
feat(core): Allow users to override the loader timeout
Fixes #177
1 parent bd0ee80 commit 94e347e

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

packages/documentation/docs/sections/internals.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ Allows you to select a language different from the language used in KG.
1616

1717
Initially, KS will just use the language KG is set at, but you can override this language here.
1818

19+
## Other internals
20+
21+
Some users may experience slow loads of KG itself, causing KS to fail to load in time, as the timeout for the loader is "only" 2 minutes.
22+
23+
In case you are impacted by this, set `localStorage["ks.timeout"]` to the amount of milliseconds KS should wait for KG to load. The default value is `120000`, which correlates to the amount of milliseconds in 2 minutes.
24+
1925
<!-- prettier-ignore-start -->
2026
*[JS]: JavaScript
2127
*[KG]: Kittens Game

packages/userscript/source/UserScript.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ export const ksVersion = (prefix = "") => {
4545
return `${prefix}${KS_VERSION}`;
4646
};
4747

48+
// How long to wait for KG to load, in milliseconds.
49+
const TIMEOUT_DEFAULT = 2 * 60 * 1000;
50+
51+
// Allows the user to define a timeout override in their browser's web storage.
52+
// This allows users to extend the timeout period, in case their local configuration
53+
// requires it.
54+
const TIMEOUT_OVERRIDE = !isNil(localStorage["ks.timeout"])
55+
? Number(localStorage["ks.timeout"])
56+
: undefined;
57+
4858
export class UserScript {
4959
readonly gamePage: GamePage;
5060

@@ -254,7 +264,7 @@ export class UserScript {
254264
return state[0];
255265
}
256266

257-
static async waitForGame(timeout = 30000): Promise<GamePage> {
267+
static async waitForGame(timeout = TIMEOUT_OVERRIDE ?? TIMEOUT_DEFAULT): Promise<GamePage> {
258268
const signals: Array<Promise<unknown>> = [sleep(2000)];
259269

260270
if (isNil(UserScript._gameStartSignal) && typeof UserScript.window.dojo !== "undefined") {

0 commit comments

Comments
 (0)