navflow-browser-server
Version:
Standalone Playwright browser server for NavFlow - enables browser automation with API key authentication, workspace device management, session sync, LLM discovery tools, and requires Node.js v22+
114 lines (107 loc) ⢠4.38 kB
JavaScript
;
/**
* NavFlow Browser Server CLI
*
* Usage: npx navflow-browser-server [options]
*/
Object.defineProperty(exports, "__esModule", { value: true });
const PlaywrightInstaller_1 = require("./PlaywrightInstaller");
const DataDirectory_1 = require("./DataDirectory");
// CLI Arguments parsing
const args = process.argv.slice(2);
const portArg = args.find(arg => arg.startsWith('--port='));
const helpArg = args.includes('--help') || args.includes('-h');
const versionArg = args.includes('--version') || args.includes('-v');
if (helpArg) {
console.log(`
š NavFlow Browser Server
A standalone Playwright browser server that enables remote browser automation
through secure API key authentication. Perfect for running browser automation
workflows from cloud-based frontends.
Usage:
npx navflow-browser-server [options]
Options:
--port=<number> Port to run the server on (default: 3002)
--help, -h Show this help message
--version, -v Show version information
Examples:
npx navflow-browser-server
npx navflow-browser-server --port=3003
Features:
ā
Playwright browser automation
ā
Secure API key authentication
ā
Auto-detection and installation of Playwright browsers
ā
Session management and flow execution
ā
Real-time WebSocket communication
Once started, copy the API key from the console and use it in your
NavFlow frontend at: https://buildship-pfw15o.web.app
For more information: https://github.com/buildship/navflow
`);
process.exit(0);
}
if (versionArg) {
const packageJson = require('../package.json');
console.log(`NavFlow Browser Server v${packageJson.version}`);
process.exit(0);
}
const PORT = portArg ? parseInt(portArg.split('=')[1]) : 3002;
if (isNaN(PORT) || PORT < 1 || PORT > 65535) {
console.error('ā Invalid port number. Please provide a port between 1 and 65535.');
process.exit(1);
}
// Welcome message
console.log('š NavFlow Browser Server');
console.log('ā'.repeat(50));
console.log(`š¦ Starting browser automation server...`);
console.log(`š Port: ${PORT}`);
console.log('');
// Check prerequisites and start server
const checkPrerequisitesAndStart = async () => {
try {
// First check Node.js version before doing anything else
const nodeCheck = PlaywrightInstaller_1.PlaywrightInstaller.checkNodeVersion();
if (!nodeCheck.valid) {
PlaywrightInstaller_1.PlaywrightInstaller.displayNodeVersionError();
process.exit(1);
}
console.log('š Checking system requirements...');
// Check and install Playwright browsers if needed
await PlaywrightInstaller_1.PlaywrightInstaller.ensurePlaywrightBrowsers();
// Display system status
await PlaywrightInstaller_1.PlaywrightInstaller.displaySystemStatus();
// Initialize data directories and show location
console.log('š Initializing data directories...');
await DataDirectory_1.DataDirectory.ensureDirectories();
// Check for and perform data migration if needed
const migration = await DataDirectory_1.DataDirectory.migrateLegacyData();
if (migration.migrated) {
console.log('ā
Session data migration completed successfully!');
}
if (migration.errors.length > 0) {
console.log('ā ļø Migration warnings:');
migration.errors.forEach(error => console.log(` ${error}`));
}
// Display data directory info
DataDirectory_1.DataDirectory.displayInfo();
console.log('');
console.log('ā
Prerequisites check complete. Starting server...');
console.log('');
// Import and start the main server
require('./index');
}
catch (error) {
console.error('ā Failed to initialize browser server:', error);
console.log('');
console.log('š” Troubleshooting tips:');
console.log(' ⢠Ensure Node.js version >= 22.0.0');
console.log(' ⢠Check internet connection for Playwright download');
console.log(' ⢠Try running: npx playwright install');
console.log(' ⢠Check disk space (Playwright browsers need ~1GB)');
console.log('');
process.exit(1);
}
};
// Start the server
checkPrerequisitesAndStart();
//# sourceMappingURL=cli.js.map