UNPKG

@gramercytech/gx-toolkit

Version:
69 lines (58 loc) • 2.01 kB
#!/usr/bin/env node const path = require("path"); const fs = require("fs"); /** * Launches Chrome with the browser extension loaded */ async function launchChromeWithExtension() { // Dynamic import for chrome-launcher (ES module) const { launch } = await import("chrome-launcher"); // Use environment variable if set (from CLI), otherwise use default path const extensionPath = process.env.CHROME_EXTENSION_PATH || path.resolve(__dirname, "../browser-extensions/chrome"); // Verify extension directory exists if (!fs.existsSync(extensionPath)) { console.error("āŒ Chrome extension directory not found:", extensionPath); process.exit(1); } // Verify manifest.json exists const manifestPath = path.join(extensionPath, "manifest.json"); if (!fs.existsSync(manifestPath)) { console.error("āŒ Chrome extension manifest.json not found"); process.exit(1); } console.log("šŸš€ Launching Chrome with extension..."); console.log("šŸ“ Extension path:", extensionPath); try { const chrome = await launch({ chromeFlags: [ `--load-extension=${extensionPath}`, "--disable-extensions-except=" + extensionPath, "--disable-extensions-file-access-check", "--user-data-dir=/tmp/chrome-extension-test", "--new-window", "--no-first-run", "--no-default-browser-check", ], startingUrl: "chrome://extensions/", }); console.log("āœ… Chrome launched successfully!"); console.log("šŸ”§ Chrome debugging port:", chrome.port); console.log("šŸ“‹ Extension should be loaded in developer mode"); console.log("🌐 Navigate to chrome://extensions/ to see your extension"); // Keep the process alive process.on("SIGINT", async () => { console.log("\nšŸ›‘ Shutting down Chrome..."); await chrome.kill(); process.exit(0); }); } catch (error) { console.error("āŒ Failed to launch Chrome:", error.message); process.exit(1); } } if (require.main === module) { launchChromeWithExtension(); } module.exports = launchChromeWithExtension;