| 380 | } |
| 381 | |
| 382 | protected async _startSession(socket: net.Socket, telemetryReporter: ITelemetryReporter) { |
| 383 | if (!this.run) { |
| 384 | return; |
| 385 | } |
| 386 | |
| 387 | const { connection, cdp, targetInfo } = await this.acquireTarget( |
| 388 | socket, |
| 389 | telemetryReporter, |
| 390 | this.run.logger, |
| 391 | ); |
| 392 | if (!this.run) { |
| 393 | // if we aren't running a session, discard the socket. |
| 394 | socket.destroy(); |
| 395 | return; |
| 396 | } |
| 397 | |
| 398 | if (targetInfo.processId === undefined) { |
| 399 | targetInfo.processId = Number(targetInfo.targetId); // old bootloaders |
| 400 | } |
| 401 | |
| 402 | let livingOpenerId = targetInfo.openerId; |
| 403 | while ( |
| 404 | livingOpenerId && !this.targets.get(livingOpenerId) && this.seenOpeners.has(livingOpenerId) |
| 405 | ) { |
| 406 | livingOpenerId = this.seenOpeners.get(livingOpenerId)?.openedBy; |
| 407 | } |
| 408 | |
| 409 | const target = new NodeTarget( |
| 410 | this.run.params, |
| 411 | this.run.context.targetOrigin, |
| 412 | connection, |
| 413 | cdp, |
| 414 | targetInfo, |
| 415 | this.run.logger, |
| 416 | this.createLifecycle(cdp, this.run, targetInfo), |
| 417 | livingOpenerId ? this.targets.get(livingOpenerId) : undefined, |
| 418 | ); |
| 419 | |
| 420 | this.seenOpeners.set(targetInfo.targetId, { openedBy: targetInfo.openerId }); |
| 421 | this.listenToWorkerDomain(cdp, telemetryReporter, target); |
| 422 | this.targets.add(targetInfo.targetId, target); |
| 423 | target.onDisconnect(() => this.targets.remove(targetInfo.targetId)); |
| 424 | } |
| 425 | |
| 426 | private async listenToWorkerDomain( |
| 427 | cdp: Cdp.Api, |