Skip to content

Commit 631a4d9

Browse files
Workaround electron proxy issues for GitHub by allowing to switch to node's fetch (microsoft#261099)
A user reported that their proxy ZScaller has issues with Electron's fetch. More research needs to be done to understand why this is not playing nice wholistically... ... but, to unblock GitHub scenarios like Copilot, we add this setting to change the implementation of fetch used. At some point, we need to have http.useElectronFetch setting be enabled by default and when that happens, this setting can be removed in favor of that. cc @chrmarti @alexdima
1 parent 2aa3c62 commit 631a4d9

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

extensions/github-authentication/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@
5555
"type": "string",
5656
"markdownDescription": "%config.github-enterprise.uri.description%",
5757
"pattern": "^(?:$|(https?)://(?!github\\.com).*)"
58+
},
59+
"github-authentication.useElectronFetch": {
60+
"type": "boolean",
61+
"default": true,
62+
"scope": "application",
63+
"markdownDescription": "%config.github-authentication.useElectronFetch.description%"
5864
}
5965
}
6066
}

extensions/github-authentication/package.nls.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"displayName": "GitHub Authentication",
33
"description": "GitHub Authentication Provider",
44
"config.github-enterprise.title": "GHE.com & GitHub Enterprise Server Authentication",
5-
"config.github-enterprise.uri.description": "The URI for your GHE.com or GitHub Enterprise Server instance.\n\nExamples:\n* GHE.com: `https://octocat.ghe.com`\n* GitHub Enterprise Server: `https://github.octocat.com`\n\n> **Note:** This should _not_ be set to a GitHub.com URI. If your account exists on GitHub.com or is a GitHub Enterprise Managed User, you do not need any additional configuration and can simply log in to GitHub."
5+
"config.github-enterprise.uri.description": "The URI for your GHE.com or GitHub Enterprise Server instance.\n\nExamples:\n* GHE.com: `https://octocat.ghe.com`\n* GitHub Enterprise Server: `https://github.octocat.com`\n\n> **Note:** This should _not_ be set to a GitHub.com URI. If your account exists on GitHub.com or is a GitHub Enterprise Managed User, you do not need any additional configuration and can simply log in to GitHub.",
6+
"config.github-authentication.useElectronFetch.description": "When true, uses Electron's built-in fetch function for HTTP requests. When false, uses the Node.js global fetch function. This setting only applies when running in the Electron environment. **Note:** A restart is required for this setting to take effect."
67
}

extensions/github-authentication/src/extension.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,21 @@ export function activate(context: vscode.ExtensionContext) {
7979
}
8080
}
8181
}));
82+
83+
// Listener to prompt for reload when the fetch implementation setting changes
84+
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(async e => {
85+
if (e.affectsConfiguration('github-authentication.useElectronFetch')) {
86+
const selection = await vscode.window.showInformationMessage(
87+
vscode.l10n.t('GitHub Authentication - Reload required'),
88+
{
89+
modal: true,
90+
detail: vscode.l10n.t('A reload is required for the fetch setting change to take effect.')
91+
},
92+
vscode.l10n.t('Reload Window')
93+
);
94+
if (selection) {
95+
await vscode.commands.executeCommand('workbench.action.reloadWindow');
96+
}
97+
}
98+
}));
8299
}

extensions/github-authentication/src/node/fetch.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,19 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import { workspace } from 'vscode';
7+
68
let _fetch: typeof fetch;
7-
try {
8-
_fetch = require('electron').net.fetch;
9-
} catch {
9+
10+
const useElectronFetch = workspace.getConfiguration('github-authentication').get<boolean>('useElectronFetch', true);
11+
if (useElectronFetch) {
12+
try {
13+
_fetch = require('electron').net.fetch;
14+
} catch {
15+
_fetch = fetch;
16+
}
17+
} else {
1018
_fetch = fetch;
1119
}
20+
1221
export const fetching = _fetch;

0 commit comments

Comments
 (0)