import { startExtensionHost } from '../../api/ext-host/extension-host';
import { createWebWorkerMessageTransports } from '@workbench-stack/extension-api';

/**
 * The entrypoint for the JavaScript context that runs the extension host (and all extensions).
 *
 * To initialize the extension host, the parent sends it an 'initialize' message with
 * {@link InitData}.
 */
async function extensionHostMain(): Promise<void> {

    try {
        const { unsubscribe } = startExtensionHost(createWebWorkerMessageTransports(), true);
        self.addEventListener('unload', () => unsubscribe());
    } catch (err) {
        console.error('Error starting the extension host:', err);
        self.close();
    }
}

extensionHostMain();
