From 8d81890e47b6669993c52b1b7fe833b71fe2fef4 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Wed, 18 Aug 2021 07:27:45 -0700 Subject: [PATCH] feat(codegen): support --save-trace option (#8267) --- src/cli/cli.ts | 7 ++ src/server/supplements/recorderSupplement.ts | 88 +++++++++++++------- tests/inspector/cli-codegen-2.spec.ts | 8 ++ 3 files changed, 73 insertions(+), 30 deletions(-) diff --git a/src/cli/cli.ts b/src/cli/cli.ts index 494eeaa433..82b44d3cea 100755 --- a/src/cli/cli.ts +++ b/src/cli/cli.ts @@ -270,6 +270,7 @@ type Options = { loadStorage?: string; proxyServer?: string; saveStorage?: string; + saveTrace?: string; timeout: string; timezone?: string; viewportSize?: string; @@ -386,6 +387,8 @@ async function launchContext(options: Options, headless: boolean, executablePath if (closingBrowser) return; closingBrowser = true; + if (options.saveTrace) + await context.tracing.stop({ path: options.saveTrace }); if (options.saveStorage) await context.storageState({ path: options.saveStorage }).catch(e => null); await browser.close(); @@ -406,6 +409,9 @@ async function launchContext(options: Options, headless: boolean, executablePath context.setDefaultNavigationTimeout(parseInt(options.timeout, 10)); } + if (options.saveTrace) + await context.tracing.start({ screenshots: true, snapshots: true }); + // Omit options that we add automatically for presentation purpose. delete launchOptions.headless; delete launchOptions.executablePath; @@ -548,6 +554,7 @@ function commandWithOpenOptions(command: string, description: string, options: a .option('--lang ', 'specify language / locale, for example "en-GB"') .option('--proxy-server ', 'specify proxy server, for example "http://myproxy:3128" or "socks5://myproxy:8080"') .option('--save-storage ', 'save context storage state at the end, for later use with --load-storage') + .option('--save-trace ', 'record a trace for the session and save it to a file') .option('--timezone