src/vs/workbench/services/extensions/browser/webWorkerExtensionHost.ts/WebWorkerExtensionHost/_startOutsideIframe
class WebWorkerExtensionHost:	private async _startOutsideIframe(): Promise<IMessagePassingProtocol> {
		const emitter = new Emitter<VSBuffer>();

		const url = getWorkerBootstrapUrl(FileAccess.asBrowserUri('../worker/extensionHostWorkerMain.js', require).toString(true), 'WorkerExtensionHost');
		const worker = new Worker(ttPolicy?.createScriptURL(url) as unknown as string ?? url, { name: 'WorkerExtensionHost' });

		const barrier = new Barrier();
		let port!: MessagePort;

		const nestedWorker = new Map<string, Worker>();

		worker.onmessage = (event) => {

			const data: MessagePort | NewWorkerMessage | TerminateWorkerMessage = event.data;

			if (data instanceof MessagePort) {
				// receiving a message port which is used to communicate
				// with the web worker extension host
				if (barrier.isOpen()) {
					console.warn('UNEXPECTED message', event);
					this._onDidExit.fire([ExtensionHostExitCode.UnexpectedError, 'received a message port AFTER opening the barrier']);
					return;
				}
				port = data;
				barrier.open();


			} else if (data?.type === '_newWorker') {
				// receiving a message to create a new nested/child worker
				const worker = new Worker((ttPolicyNestedWorker?.createScriptURL(data.url) ?? data.url) as string, data.options);
				worker.postMessage(data.port, [data.port]);
				worker.onerror = console.error.bind(console);
				nestedWorker.set(data.id, worker);

			} else if (data?.type === '_terminateWorker') {
				// receiving a message to terminate nested/child worker
				if (nestedWorker.has(data.id)) {
					nestedWorker.get(data.id)!.terminate();
					nestedWorker.delete(data.id);
				}

			} else {
				// all other messages are an error
				console.warn('UNEXPECTED message', event);
				this._onDidExit.fire([ExtensionHostExitCode.UnexpectedError, 'UNEXPECTED message']);
			}
		};

		// await MessagePort and use it to directly communicate
		// with the worker extension host
		await barrier.wait();

		port.onmessage = (event) => {
			const { data } = event;
			if (!(data instanceof ArrayBuffer)) {
				console.warn('UNKNOWN data received', data);
				this._onDidExit.fire([77, 'UNKNOWN data received']);
				return;
			}

			emitter.fire(VSBuffer.wrap(new Uint8Array(data, 0, data.byteLength)));
		};

		worker.onerror = (event) => {
			console.error(event.message, event.error);
			this._onDidExit.fire([ExtensionHostExitCode.UnexpectedError, event.message || event.error]);
		};

		// keep for cleanup
		this._register(emitter);
		this._register(toDisposable(() => worker.terminate()));

		const protocol: IMessagePassingProtocol = {
			onMessage: emitter.event,
			send: vsbuf => {
				const data = vsbuf.buffer.buffer.slice(vsbuf.buffer.byteOffset, vsbuf.buffer.byteOffset + vsbuf.buffer.byteLength);
				port.postMessage(data, [data]);
			}
		};

		return this._performHandshake(protocol);
	}