public async launch()

in src/edgeChromiumDebugAdapter.ts [39:113]


    public async launch(args: ILaunchRequestArgs, telemetryPropertyCollector: ITelemetryPropertyCollector, seq?: number) {
        let attachToWebView = false;

        const webViewReadyToAttach = new Promise<number>((resolve, reject) => {
            this._webViewCreatedCallback = resolve;
        });

        if (args.useWebView) {
            if (!args.runtimeExecutable) {
                // Users must specify the host application via runtimeExecutable when using webview
                return errors.incorrectFlagMessage('runtimeExecutable', 'Must be set when using \'useWebView\'');
            }

            const webViewTelemetry = (args.useWebView === 'advanced' ? 'advanced' : 'true');
            telemetryPropertyCollector.addTelemetryProperty('useWebView', webViewTelemetry);
            this._isDebuggerUsingWebView = true;

            if (!args.noDebug) {
                // Initialize WebView debugging environment variables
                args.env = args.env || {};

                if (args.useWebView === 'advanced') {
                    // Advanced scenarios should use port 0 by default since we expect the callback to inform us of the correct port
                    if (!args.port || args.port === 2015) {
                        args.port = 0;
                    }

                    // Create the webview server that will inform us of webview creation events
                    const pipeName = await this.createWebViewServer(args);
                    args.env['WEBVIEW2_PIPE_FOR_SCRIPT_DEBUGGER'] = pipeName;
                } else {
                    // For normal scenarios use the port specified or 2015 by default
                    args.port = args.port || 2015;
                    if (!args.userDataDir) {
                        // Also override the userDataDir to force remote debugging to be enabled
                        args.userDataDir = path.join(os.tmpdir(), `vscode-edge-debug-userdatadir_${args.port}`);
                    }
                    this._webViewCreatedCallback(args.port);
                }

                if (args.userDataDir) {
                    // WebView should not force a userDataDir (unless user specified one) so that we don't disrupt
                    // the expected behavior of the host application.
                    args.env['WEBVIEW2_USER_DATA_FOLDER'] = args.userDataDir.toString();
                }
                args.env['WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS'] = `--remote-debugging-port=${args.port}`;
                args.env['WEBVIEW2_WAIT_FOR_SCRIPT_DEBUGGER'] = 'true';
            }

            // To ensure the ChromeDebugAdapter does not override the launchUrl for WebView we force noDebug=true.
            attachToWebView = !args.noDebug;
            args.noDebug = true;
        }

        await super.launch(args, telemetryPropertyCollector, seq);

        const chromeKilledCallback = () => this.terminateSession("WebView program ended before the debugger could connect");
        if(this._chromeProc) {
            this._chromeProc.on('exit', chromeKilledCallback);
        }

        if (attachToWebView) {
            const port = await webViewReadyToAttach;

            // If we are debugging a WebView, we need to attach to it after launch.
            // Since the ChromeDebugAdapter will have been called with noDebug=true,
            // it will not have auto attached during the super.launch() call.
            if(port > 0) {
                this.doAttach(port, this.getWebViewLaunchUrl(args), args.address, args.timeout, undefined, args.extraCRDPChannelPort);
                if(this._chromeProc) {
                    this._chromeProc.removeListener('exit', chromeKilledCallback);
                }
            }
        }
    }