in src/debugger/cordovaDebugSession.ts [286:363]
protected attachRequest(response: DebugProtocol.AttachResponse, attachArgs: ICordovaAttachRequestArgs, request?: DebugProtocol.Request): Promise<void> {
return new Promise<void>((resolve, reject) => this.initializeTelemetry(attachArgs.cwd)
.then(() => {
this.initializeSettings(attachArgs);
})
.then(() => TelemetryHelper.generate("attach", (generator) => {
attachArgs.port = attachArgs.port || 9222;
attachArgs.target = attachArgs.target || TargetType.Emulator;
generator.add("target", CordovaDebugSession.getTargetType(attachArgs.target), false);
attachArgs.timeout = attachArgs.attachTimeout;
let platform = attachArgs.platform && attachArgs.platform.toLowerCase();
let target = attachArgs.target && attachArgs.target.toLowerCase();
TelemetryHelper.sendPluginsList(attachArgs.cwd, CordovaProjectHelper.getInstalledPlugins(attachArgs.cwd));
return TelemetryHelper.determineProjectTypes(attachArgs.cwd)
.then((projectType) => {
let sourcemapPathTransformer = new SourcemapPathTransformer(attachArgs, projectType);
this.cordovaCdpProxy = new CordovaCDPProxy(
this.cdpProxyHostAddress,
this.cdpProxyPort,
sourcemapPathTransformer,
projectType,
attachArgs
);
this.cordovaCdpProxy.setApplicationTargetPort(attachArgs.port);
generator.add("projectType", TelemetryHelper.prepareProjectTypesTelemetry(projectType), false);
return this.cordovaCdpProxy.createServer(this.cdpProxyLogLevel, this.cancellationTokenSource.token);
})
.then(() => {
if ((platform === PlatformType.Android || platform === PlatformType.IOS) && !SimulateHelper.isSimulateTarget(target)) {
this.outputLogger(localize("AttachingToPlatform", "Attaching to {0}", platform));
switch (platform) {
case PlatformType.Android:
generator.add("platform", platform, false);
return this.attachAndroid(attachArgs);
case PlatformType.IOS:
generator.add("platform", platform, false);
return this.attachIos(attachArgs);
default:
generator.add("unknownPlatform", platform, true);
throw new Error(localize("UnknownPlatform", "Unknown Platform: {0}", platform));
}
} else {
return attachArgs;
}
})
.then((processedAttachArgs: ICordovaAttachRequestArgs & { url?: string }) => {
this.outputLogger(localize("AttachingToApp", "Attaching to app"));
this.outputLogger("", true); // Send blank message on stderr to include a divider between prelude and app starting
if (this.cordovaCdpProxy) {
if (processedAttachArgs.webSocketDebuggerUrl) {
this.cordovaCdpProxy.setBrowserInspectUri(processedAttachArgs.webSocketDebuggerUrl);
}
this.cordovaCdpProxy.configureCDPMessageHandlerAccordingToProcessedAttachArgs(processedAttachArgs);
}
this.establishDebugSession(processedAttachArgs, resolve, reject);
});
})
.catch((err) => {
this.outputLogger(err.message || err.format || err, true);
return this.cleanUp().then(() => {
throw err;
});
})
)
.catch(err => reject(err))
)
.then(() => {
this.attachedDeferred.resolve();
this.sendResponse(response);
this.cordovaSession.setStatus(CordovaSessionStatus.Activated);
})
.catch(err => {
this.showError(err, response);
});
}