export async function recordJourney()

in electron/api/recordJourney.ts [33:72]


export async function recordJourney(
  _event: IpcMainInvokeEvent,
  url: string,
  browserManager: BrowserManager
) {
  const browserWindow = BrowserWindow.getFocusedWindow()!;
  try {
    const { browser, context } = await browserManager.launchBrowser();
    const actionListener = new EventEmitter();

    ipcMain.handleOnce('stop-recording', async () => {
      actionListener.removeListener('actions', actionsHandler);
      await browserManager.closeBrowser();
    });

    // Listen to actions from Playwright recording session
    const actionsHandler = (actions: ActionInContext[]) => {
      browserWindow.webContents.send('actions-generated', actions);
    };
    actionListener.on('actions', actionsHandler);

    // setting this will prevent the playwright inspector window opening;
    // we don't use this for anything and it's confusing and cluttering to the user
    process.env.PWTEST_CLI_HEADLESS = 'true';
    // _enableRecorder is private method, not defined in BrowserContext type
    await (context as any)._enableRecorder({
      launchOptions: {},
      contextOptions: {},
      mode: 'recording',
      showRecorder: false,
      actionListener,
    });
    await openPage(context, url);
    await once(browser, 'disconnected');
  } catch (e) {
    logger.error(e);
  } finally {
    ipcMain.removeHandler('stop-recording');
  }
}