Skip to content

Commit 591eb06

Browse files
authored
fix(compass): disable spellcheck before creating window when no network traffic COMPASS-8166 (#6853)
1 parent 2d7c937 commit 591eb06

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

packages/compass-e2e-tests/tests/no-network-traffic.test.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ describe('networkTraffic: false / Isolated Edition', function () {
6565
const compass = await init(this.test?.fullTitle(), {
6666
extraSpawnArgs: ['--no-network-traffic'],
6767
wrapBinary,
68-
// TODO(COMPASS-8166): firstRun: true seems to result in network traffic.
69-
// Probably the welcome modal.
70-
firstRun: false,
68+
firstRun: true,
7169
});
7270
const browser = compass.browser;
7371

@@ -117,7 +115,11 @@ describe('networkTraffic: false / Isolated Edition', function () {
117115

118116
if (
119117
[...connectTargets].some(
120-
(target) => !/^127.0.0.1:|^\[::1\]:/.test(target)
118+
// Chromium heuristically detects IPv4-only networks by attempting a UDP connection
119+
// to 2001:4860:4860::8888 (the IPv6 address for Google Public DNS).
120+
(target) =>
121+
!/^127.0.0.1:|^\[::1\]:/.test(target) &&
122+
!/^\[2001:4860:4860::8888\]:443$/.test(target)
121123
)
122124
) {
123125
throw new Error(`Connected to unexpected host! ${[...connectTargets]}`);

packages/compass/src/main/application.ts

+14
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,20 @@ class CompassApplication {
130130
// Accessing isEncryptionAvailable is not allowed when app is not ready on Windows
131131
// https://github.com/electron/electron/issues/33640
132132
await app.whenReady();
133+
134+
const { networkTraffic } = this.preferences.getPreferences();
135+
136+
if (!networkTraffic) {
137+
// Electron fetches spellcheck dictionaries from a CDN
138+
// on all OSs expect mac (it provides a built-in spell check).
139+
// Passing a non-resolving URL prevents it from fetching
140+
// as there aren't any options to disable it provided.
141+
// https://github.com/electron/electron/issues/22995
142+
session.defaultSession.setSpellCheckerDictionaryDownloadURL(
143+
'http://127.0.0.1:0/'
144+
);
145+
}
146+
133147
log.info(
134148
mongoLogId(1_001_000_307),
135149
'Application',

packages/compass/src/main/window-manager.ts

-9
Original file line numberDiff line numberDiff line change
@@ -140,22 +140,13 @@ function showConnectWindow(
140140
};
141141

142142
debug('creating new main window:', windowOpts);
143-
const { preferences } = compassApp;
144-
const { networkTraffic } = preferences.getPreferences();
145-
146143
let window: BrowserWindow | null = new BrowserWindow(windowOpts);
147144
if (mongodbUrl) {
148145
registerMongoDbUrlForBrowserWindow(window, mongodbUrl);
149146
}
150147
if (connectionId) {
151148
registerConnectionIdForBrowserWindow(window, connectionId);
152149
}
153-
if (networkTraffic !== true) {
154-
// https://github.com/electron/electron/issues/22995
155-
window.webContents.session.setSpellCheckerDictionaryDownloadURL(
156-
'http://127.0.0.1:0/'
157-
);
158-
}
159150

160151
enable(window.webContents);
161152
const unsubscribeProxyListenerPromise = compassApp.setupProxySupport(

0 commit comments

Comments
 (0)