@gramercytech/gx-toolkit
Version:
Dev tools for create platform plugins
69 lines (58 loc) ⢠2.01 kB
JavaScript
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;