"use strict";var __create=Object.create,__defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty,__export=(e,o)=>{for(var t in o)__defProp(e,t,{get:o[t],enumerable:!0})},__copyProps=(e,o,t,r)=>{if(o&&"object"==typeof o||"function"==typeof o)for(let s of __getOwnPropNames(o))__hasOwnProp.call(e,s)||s===t||__defProp(e,s,{get:()=>o[s],enumerable:!(r=__getOwnPropDesc(o,s))||r.enumerable});return e},__toESM=(e,o,t)=>(t=null!=e?__create(__getProtoOf(e)):{},__copyProps(!o&&e&&e.__esModule?t:__defProp(t,"default",{value:e,enumerable:!0}),e)),__toCommonJS=e=>__copyProps(__defProp({},"__esModule",{value:!0}),e),output_exports={};__export(output_exports,{JsonOutput:()=>JsonOutput,TextOutput:()=>TextOutput}),module.exports=__toCommonJS(output_exports);var import_path=__toESM(require("path")),import_extension=require("../utils/extension");class TextOutput{constructor(){this.json=!1}version(e){console.log(e)}help(e){console.log(e)}errorUnknownCommand(e,o){return console.error(`Unknown command: ${e}
`),console.log(o),process.exit(1)}errorUnknownOption(e,o){return console.error(`Unknown option${e.length>1?"s":""}: ${e.map(e=>`--${e}`).join(", ")}`),console.log(""),console.log(o),process.exit(1)}errorTooManyArguments(e,o,t){return console.error(`error: too many arguments: expected ${e}, received ${o}`),console.log(""),console.log(t),process.exit(1)}errorAttachConflict(){return console.error("Error: cannot use target name with --cdp, --endpoint, or --extension"),process.exit(1)}errorDetachNotAttached(e){return console.error(`Error: session '${e}' was not attached; use \`playwright-cli${"default"!==e?` -s=${e}`:""} close\` to stop it.`),process.exit(1)}errorBrowserNotOpenForTool(e){return console.log(`The browser '${e}' is not open, please run open first`),console.log(""),console.log(`  playwright-cli${"default"!==e?` -s=${e}`:""} open [params]`),process.exit(1)}errorAttachNoTarget(){return console.error("Error: no target specified for attach command; use one of [name], --cdp, --endpoint, or --extension to specify the target to attach to."),process.exit(1)}list({all:e,browsers:o,servers:t,channelSessions:r}){let s=new Map;for(let e of o){let o=s.get(e.workspace);o||(o=[],s.set(e.workspace,o)),o.push(e)}let n=0;for(let[o,t]of s){for(let r of(0===n&&console.log("### Browsers"),e&&console.log(`${import_path.default.relative(process.cwd(),o)||"/"}:`),t))console.log(renderBrowser(r));n+=t.length}if(!e){n||console.log("  (no browsers)");return}if(t?.length){n&&console.log(""),console.log("### Browser servers available for attach");let e=new Map;for(let o of t){let t=e.get(o.workspaceDir??"");t||(t=[],e.set(o.workspaceDir??"",t)),t.push(o)}for(let[o,t]of e)for(let e of(o&&console.log(`${import_path.default.relative(process.cwd(),o)||"/"}:`),t))console.log(renderServer(e));n+=t.length}if(n||console.log("  (no browsers)"),r?.length)for(let e of(console.log(""),console.log("### Browsers available to attach via CDP"),r))console.log(renderChannelSession(e))}closeAll(e){}deleteData(e,o){o.existed?o.deletedUserDataDir&&console.log(`Deleted user data for browser '${e}'.`):console.log(`No user data found for browser '${e}'.`)}killAll(e){for(let o of e)console.log(`Killed daemon process ${o}`);0===e.length?console.log("No daemon processes found."):console.log(`Killed ${e.length} daemon process${1===e.length?"":"es"}.`)}open(e,o,t){console.log(`### Browser \`${e}\` opened with pid ${o}.`),t&&console.log(t)}attach(e,o,t,r){t?(console.log(`### Session \`${e}\` created, attached to \`${t}\`.`),console.log(`Run commands with: playwright-cli --s=${e} <command>`),console.log("")):console.log(`### Browser \`${e}\` opened with pid ${o}.`),r&&console.log(r)}close(e,o){o?console.log(`Browser '${e}' closed
`):console.log(`Browser '${e}' is not open.`)}detach(e,o){o?console.log(`Browser '${e}' detached
`):console.log(`Browser '${e}' is not attached.`)}installed(){}show(e,o){process.env.PWTEST_PRINT_DASHBOARD_PID_FOR_TEST&&console.log(`### Dashboard opened with pid ${o}.`)}toolResult(e){console.log(e)}installStdio(){return"inherit"}}class JsonOutput{constructor(){this.json=!0}version(e){this._emit({version:e})}help(e){this._emit({help:e})}errorUnknownCommand(e,o){return this._emit({isError:!0,error:`Unknown command: ${e}`}),process.exit(1)}errorUnknownOption(e,o){return this._emit({isError:!0,error:`Unknown option${e.length>1?"s":""}: ${e.map(e=>`--${e}`).join(", ")}`}),process.exit(1)}errorTooManyArguments(e,o,t){return this._emit({isError:!0,error:`error: too many arguments: expected ${e}, received ${o}`}),process.exit(1)}errorAttachConflict(){return this._emit({isError:!0,error:"cannot use target name with --cdp, --endpoint, or --extension"}),process.exit(1)}errorDetachNotAttached(e){return this._emit({isError:!0,error:`session '${e}' was not attached; use close to stop it.`}),process.exit(1)}errorBrowserNotOpenForTool(e){return this._emit({isError:!0,error:`The browser '${e}' is not open, please run open first`}),process.exit(1)}errorAttachNoTarget(){return this._emit({isError:!0,error:"no target specified for attach command; use one of [name], --cdp, --endpoint, or --extension to specify the target to attach to."}),process.exit(1)}list({all:e,browsers:o,servers:t,channelSessions:r}){let s={browsers:o};e&&(s.servers=t??[],s.channelSessions=r??[]),this._emit(s)}closeAll(e){this._emit({closed:e})}deleteData(e,o){this._emit({session:e,deleted:o.existed})}killAll(e){this._emit({killed:e.length,pids:e})}open(e,o,t){this._emit({session:e,pid:o,result:parseJsonText(t)})}attach(e,o,t,r){this._emit({session:e,pid:o,...t?{endpoint:t}:{},result:parseJsonText(r)})}close(e,o){this._emit({session:e,status:o?"closed":"not-open"})}detach(e,o){this._emit({session:e,status:o?"detached":"not-attached"})}installed(){this._emit({installed:!0})}show(e,o){this._emit({session:e,pid:o})}toolResult(e){console.log(e)}installStdio(){return"ignore"}_emit(e){console.log(JSON.stringify(e,null,2))}}function parseJsonText(e){try{return JSON.parse(e)}catch{return e}}function renderBrowser(e){let o=[`- ${e.name}:`];return o.push(`  - status: ${e.status}`),"open"!==e.status||e.compatible||o.push(`  - version: v${e.version} [incompatible please re-open]`),e.browserType&&o.push(`  - browser-type: ${e.browserType}${e.attached?" (attached)":""}`),e.attached||(null===e.userDataDir?o.push("  - user-data-dir: <in-memory>"):o.push(`  - user-data-dir: ${e.userDataDir}`),void 0!==e.headed&&o.push(`  - headed: ${e.headed}`)),o.join("\n")}function renderServer(e){let o=[`- browser "${e.title}":`];return o.push(`  - browser: ${e.browser.browserName}`),o.push(`  - version: v${e.playwrightVersion}`),e.browser.userDataDir?o.push(`  - data-dir: ${e.browser.userDataDir}`):o.push("  - data-dir: <in-memory>"),o.push(`  - run \`playwright-cli attach "${e.title}"\` to attach`),o.join("\n")}function renderChannelSession(e){let o=[`- ${e.channel}:`];if(o.push(`  - data-dir: ${e.userDataDir}`),e.extensionInstalled?o.push(`  - attach (extension): \`playwright-cli attach --extension=${e.channel}\``):o.push(`  - attach (extension): install at ${import_extension.playwrightExtensionInstallUrl}`),e.endpoint)o.push(`  - attach (remote debugging): \`playwright-cli attach --cdp=${e.channel}\``);else{let t=e.channel.startsWith("msedge")?"edge":"chrome";o.push(`  - attach (remote debugging): enable at ${t}://inspect/#remote-debugging`)}return o.join("\n")}