-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(odd): pretend to be online all the time (#13746)
For some reason, when the ODD starts and the robot boots while not connected to any network, some (some!) requests to localhost will fail. It's really strange. One thing that seems to help is pretending to be online by overriding the navigator.onLine browser api to always return true. --------- Co-authored-by: Jamey H <[email protected]>
- Loading branch information
Showing
5 changed files
with
27 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const hackWindowNavigatorOnLine = (): void => {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// If the system boots while no network connection is available, then some requests to localhost | ||
// hang eternally while connecting (so no request timeouts work either) and things get | ||
// generally weird. Overriding the browser API to pretend to always be "online" fixes this. | ||
// It makes sense; if "onLine" is false, that means that any network call is _guaranteed_ to fail | ||
// so middlewares probably elide them; but we really want it to be true basically always because | ||
// most of what we do is via localhost. | ||
// | ||
// This function is exposed in its own module so it can be mocked in testing | ||
// since jest really doesn't like you doing this. | ||
|
||
export const hackWindowNavigatorOnLine = (): void => { | ||
Object.defineProperty(window.navigator, 'onLine', { | ||
get: () => true, | ||
}) | ||
window.dispatchEvent(new Event('online')) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters