chrome-ai-bridge 1.0.17 → 1.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,7 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
+ import { execSync } from 'node:child_process';
6
7
  import fs from 'node:fs';
7
8
  import os from 'node:os';
8
9
  import path from 'node:path';
@@ -421,7 +422,7 @@ export function getDevelopmentExtensionPaths() {
421
422
  return developmentExtensionPaths;
422
423
  }
423
424
  export async function launch(options) {
424
- const { channel, executablePath, customDevTools, headless, isolated, loadExtension, loadExtensionsDir, loadSystemExtensions, chromeProfile, } = options;
425
+ const { channel, executablePath, customDevTools, headless, isolated, loadExtension, loadExtensionsDir, loadSystemExtensions, chromeProfile, focus = false, } = options;
425
426
  // Reset development extension paths
426
427
  developmentExtensionPaths = [];
427
428
  // Resolve user data directory using new profile resolver (v0.15.0+)
@@ -562,6 +563,27 @@ export async function launch(options) {
562
563
  }
563
564
  let browser;
564
565
  let finalUserDataDir = userDataDir;
566
+ // Remember current foreground app before Chrome launch (for background mode)
567
+ let previousApp = null;
568
+ if (!focus && !effectiveHeadless && os.platform() === 'darwin') {
569
+ try {
570
+ previousApp = execSync(`osascript -e 'tell application "System Events" to get name of first application process whose frontmost is true'`, { encoding: 'utf-8', timeout: 5000 }).trim();
571
+ console.error(`📋 Current foreground app: ${previousApp}`);
572
+ }
573
+ catch (error) {
574
+ console.warn(`⚠️ Could not detect foreground app: ${error instanceof Error ? error.message : String(error)}`);
575
+ }
576
+ }
577
+ // Windows/Linux: Add --start-minimized for background mode
578
+ if (!focus && !effectiveHeadless && os.platform() !== 'darwin') {
579
+ args.push('--start-minimized');
580
+ console.error('📋 Added --start-minimized for background mode');
581
+ }
582
+ // All platforms: Add --no-startup-window for background mode
583
+ if (!focus && !effectiveHeadless) {
584
+ args.push('--no-startup-window');
585
+ console.error('📋 Added --no-startup-window for background mode');
586
+ }
565
587
  try {
566
588
  browser = await puppeteer.launch({
567
589
  ...connectOptions,
@@ -660,6 +682,18 @@ export async function launch(options) {
660
682
  });
661
683
  console.error('Applied navigator.webdriver bypass to existing page');
662
684
  }
685
+ // Restore focus to previous app (background mode on macOS)
686
+ if (!focus && !effectiveHeadless && previousApp && os.platform() === 'darwin') {
687
+ try {
688
+ // Small delay to ensure Chrome window is fully rendered
689
+ await new Promise(resolve => setTimeout(resolve, 500));
690
+ execSync(`osascript -e 'tell application "${previousApp}" to activate'`, { timeout: 5000 });
691
+ console.error(`✅ Restored focus to: ${previousApp}`);
692
+ }
693
+ catch (error) {
694
+ console.warn(`⚠️ Could not restore focus: ${error instanceof Error ? error.message : String(error)}`);
695
+ }
696
+ }
663
697
  return browser;
664
698
  }
665
699
  catch (error) {
package/build/src/cli.js CHANGED
@@ -79,6 +79,11 @@ export const cliOptions = {
79
79
  description: 'Explicitly specify the project root directory for profile isolation. Overrides MCP roots/list. Useful when roots/list is not available.',
80
80
  conflicts: 'browserUrl',
81
81
  },
82
+ focus: {
83
+ type: 'boolean',
84
+ description: 'Bring Chrome window to foreground on launch. By default, Chrome launches in the background to avoid interrupting your work.',
85
+ default: false,
86
+ },
82
87
  };
83
88
  export function parseArguments(version, argv = process.argv) {
84
89
  const yargsInstance = yargs(hideBin(argv))
package/build/src/main.js CHANGED
@@ -140,6 +140,7 @@ async function getContext() {
140
140
  userDataDir: args.userDataDir,
141
141
  logFile,
142
142
  rootsInfo: cachedRootsInfo, // Pass roots info to browser
143
+ focus: args.focus, // v1.0.18: Background mode control
143
144
  };
144
145
  const browser = await resolveBrowser(browserOptions);
145
146
  // Announce browser PID for graceful shutdown
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chrome-ai-bridge",
3
- "version": "1.0.17",
3
+ "version": "1.0.19",
4
4
  "description": "MCP server bridging Chrome browser and AI assistants (ChatGPT, Gemini). Browser automation + AI consultation.",
5
5
  "type": "module",
6
6
  "bin": "./scripts/cli.mjs",