From 282a5045a316f194c507265ff1c784c94996a1ef Mon Sep 17 00:00:00 2001 From: Adam Krantz Date: Sat, 20 Jul 2024 16:45:42 -0700 Subject: [PATCH] don't enable appcontainer loopback on Windows 11 --- packages/office-addin-debugging/src/start.ts | 45 +++++++++++++------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/packages/office-addin-debugging/src/start.ts b/packages/office-addin-debugging/src/start.ts index 41c617243..764a2be51 100644 --- a/packages/office-addin-debugging/src/start.ts +++ b/packages/office-addin-debugging/src/start.ts @@ -304,19 +304,35 @@ export async function startDebugging(manifestPath: string, options: StartDebuggi } // enable loopback for Edge - if (isWindowsPlatform && parseInt(os.release(), 10) === 10) { - const name = isDesktopAppType ? "EdgeWebView" : "EdgeWebBrowser"; - try { - await devSettings.ensureLoopbackIsEnabled(name); - } catch (err: any) { - // if add loopback exemption failed, report the error then continue - console.error(err) - console.warn("Failed to add loopback exemption.\nWill try to sideload the Office Add-in without the loopback exemption, but it might not load correctly from localhost.\n") - usageDataObject.reportException("startDebugging()", err, { - app: app, - document: document, - appType: appType, - }); + if (isWindowsPlatform) { + let enableLoopback = false; + const [majorVersion, , releaseVersion] = os + .release() + .split(".") + .map((version) => parseInt(version, 10)); + + if (majorVersion === 10) { + if (releaseVersion && releaseVersion >= 18362 && releaseVersion < 20000) { + enableLoopback = true; + } + } + + if (enableLoopback) { + const name = isDesktopAppType ? "EdgeWebView" : "EdgeWebBrowser"; + try { + await devSettings.ensureLoopbackIsEnabled(name, false); + } catch (err: any) { + // if add loopback exemption failed, report the error then continue + console.error(err); + console.warn( + "Failed to add loopback exemption.\nWill try to sideload the Office Add-in without the loopback exemption, but it might not load correctly from localhost.\n" + ); + usageDataObject.reportException("startDebugging()", err, { + app: app, + document: document, + appType: appType, + }); + } } } @@ -445,8 +461,7 @@ async function extractManifest(zipPath: string): Promise { const manifestPath = fspath.join(targetPath, "manifest.json"); if (fs.existsSync(manifestPath)) { return manifestPath; - } - else { + } else { throw new Error(`The zip file '${zipPath}' does not contain a "manifest.json" file`); } }