/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ /// //@ts-check 'use strict'; // Simple module style to support node.js and browser environments (function (globalThis, factory) { // Node.js if (typeof exports === 'object') { module.exports = factory(); } // Browser else { globalThis.MonacoBootstrapWindow = factory(); } }(this, function () { const bootstrapLib = bootstrap(); const preloadGlobals = sandboxGlobals(); const safeProcess = preloadGlobals.process; /** * @typedef {import('./vs/base/parts/sandbox/common/sandboxTypes').ISandboxConfiguration} ISandboxConfiguration * * @param {string[]} modulePaths * @param {(result: unknown, configuration: ISandboxConfiguration) => Promise | undefined} resultCallback * @param {{ * configureDeveloperSettings?: (config: ISandboxConfiguration) => { * forceDisableShowDevtoolsOnError?: boolean, * forceEnableDeveloperKeybindings?: boolean, * disallowReloadKeybinding?: boolean, * removeDeveloperKeybindingsAfterLoad?: boolean * }, * canModifyDOM?: (config: ISandboxConfiguration) => void, * beforeLoaderConfig?: (loaderConfig: object) => void, * beforeRequire?: () => void * }} [options] */ async function load(modulePaths, resultCallback, options) { const isDev = !!safeProcess.env['VSCODE_DEV']; // Error handler (node.js enabled renderers only) let showDevtoolsOnError = isDev; if (!safeProcess.sandboxed) { safeProcess.on('uncaughtException', function (/** @type {string | Error} */ error) { onUnexpectedError(error, showDevtoolsOnError); }); } // Await window configuration from preload const timeout = setTimeout(() => { console.error(`[resolve window config] Could not resolve window configuration within 10 seconds, but will continue to wait...`); }, 10000); performance.mark('code/willWaitForWindowConfig'); /** @type {ISandboxConfiguration} */ const configuration = await preloadGlobals.context.resolveConfiguration(); performance.mark('code/didWaitForWindowConfig'); clearTimeout(timeout); // Signal DOM modifications are now OK if (typeof options?.canModifyDOM === 'function') { options.canModifyDOM(configuration); } // Developer settings const { forceDisableShowDevtoolsOnError, forceEnableDeveloperKeybindings, disallowReloadKeybinding, removeDeveloperKeybindingsAfterLoad } = typeof options?.configureDeveloperSettings === 'function' ? options.configureDeveloperSettings(configuration) : { forceDisableShowDevtoolsOnError: false, forceEnableDeveloperKeybindings: false, disallowReloadKeybinding: false, removeDeveloperKeybindingsAfterLoad: false }; showDevtoolsOnError = isDev && !forceDisableShowDevtoolsOnError; const enableDeveloperKeybindings = isDev || forceEnableDeveloperKeybindings; let developerDeveloperKeybindingsDisposable; if (enableDeveloperKeybindings) { developerDeveloperKeybindingsDisposable = registerDeveloperKeybindings(disallowReloadKeybinding); } // Enable ASAR support (node.js enabled renderers only) if (!safeProcess.sandboxed) { globalThis.MonacoBootstrap.enableASARSupport(configuration.appRoot); } // Get the nls configuration into the process.env as early as possible const nlsConfig = globalThis.MonacoBootstrap.setupNLS(); let locale = nlsConfig.availableLanguages['*'] || 'en'; if (locale === 'zh-tw') { locale = 'zh-Hant'; } else if (locale === 'zh-cn') { locale = 'zh-Hans'; } window.document.documentElement.setAttribute('lang', locale); // Define `fs` as `original-fs` to disable ASAR support // in fs-operations (node.js enabled renderers only) if (!safeProcess.sandboxed) { require.define('fs', [], function () { return require.__$__nodeRequire('original-fs'); }); } window['MonacoEnvironment'] = {}; const loaderConfig = { baseUrl: `${bootstrapLib.fileUriFromPath(configuration.appRoot, { isWindows: safeProcess.platform === 'win32', scheme: 'vscode-file', fallbackAuthority: 'vscode-app' })}/out`, 'vs/nls': nlsConfig, preferScriptTags: true }; // use a trusted types policy when loading via script tags loaderConfig.trustedTypesPolicy = window.trustedTypes?.createPolicy('amdLoader', { createScriptURL(value) { if (value.startsWith(window.location.origin)) { return value; } throw new Error(`Invalid script url: ${value}`); } }); // Teach the loader the location of the node modules we use in renderers // This will enable to load these modules via