(options: McpLaunchOptions)
| 183 | } |
| 184 | |
| 185 | export async function launch(options: McpLaunchOptions): Promise<Browser> { |
| 186 | const {channel, executablePath, headless, isolated} = options; |
| 187 | const profileDirName = |
| 188 | channel && channel !== 'stable' |
| 189 | ? `chrome-profile-${channel}` |
| 190 | : 'chrome-profile'; |
| 191 | |
| 192 | let userDataDir = options.userDataDir; |
| 193 | if (!isolated && !userDataDir) { |
| 194 | userDataDir = path.join( |
| 195 | os.homedir(), |
| 196 | '.cache', |
| 197 | options.viaCli ? 'chrome-devtools-mcp-cli' : 'chrome-devtools-mcp', |
| 198 | profileDirName, |
| 199 | ); |
| 200 | await fs.promises.mkdir(userDataDir, { |
| 201 | recursive: true, |
| 202 | }); |
| 203 | } |
| 204 | |
| 205 | const args: LaunchOptions['args'] = [ |
| 206 | ...(options.chromeArgs ?? []), |
| 207 | '--hide-crash-restore-bubble', |
| 208 | ]; |
| 209 | const ignoreDefaultArgs: LaunchOptions['ignoreDefaultArgs'] = |
| 210 | options.ignoreDefaultChromeArgs ?? false; |
| 211 | |
| 212 | if (headless) { |
| 213 | args.push('--screen-info={3840x2160}'); |
| 214 | } |
| 215 | let puppeteerChannel: ChromeReleaseChannel | undefined; |
| 216 | if (options.devtools) { |
| 217 | args.push('--auto-open-devtools-for-tabs'); |
| 218 | } |
| 219 | if (!executablePath) { |
| 220 | puppeteerChannel = |
| 221 | channel && channel !== 'stable' |
| 222 | ? (`chrome-${channel}` as ChromeReleaseChannel) |
| 223 | : 'chrome'; |
| 224 | } |
| 225 | |
| 226 | if (!headless) { |
| 227 | detectDisplay(); |
| 228 | } |
| 229 | |
| 230 | try { |
| 231 | const browser = await puppeteer.launch({ |
| 232 | channel: puppeteerChannel, |
| 233 | targetFilter: makeTargetFilter(options.enableExtensions), |
| 234 | executablePath, |
| 235 | defaultViewport: null, |
| 236 | userDataDir, |
| 237 | pipe: true, |
| 238 | headless, |
| 239 | args, |
| 240 | ignoreDefaultArgs: ignoreDefaultArgs, |
| 241 | acceptInsecureCerts: options.acceptInsecureCerts, |
| 242 | handleDevToolsAsPage: true, |
no test coverage detected
searching dependent graphs…