navflow-browser-server
Version:
Standalone Playwright browser server for NavFlow - enables browser automation with API key authentication, workspace device management, session sync, and requires Node.js v22+
219 lines • 8.56 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.PlaywrightInstaller = void 0;
const child_process_1 = require("child_process");
const util_1 = require("util");
const execAsync = (0, util_1.promisify)(child_process_1.exec);
class PlaywrightInstaller {
/**
* Check if Node.js version meets requirements
*/
static checkNodeVersion() {
const nodeVersion = process.version;
const currentMajor = parseInt(nodeVersion.substring(1).split('.')[0]);
return {
valid: currentMajor >= this.REQUIRED_NODE_VERSION,
current: nodeVersion,
required: `v${this.REQUIRED_NODE_VERSION}+`
};
}
/**
* Display Node.js version error and exit
*/
static displayNodeVersionError() {
const versionCheck = this.checkNodeVersion();
console.log('');
console.log('❌ INCOMPATIBLE NODE.JS VERSION');
console.log('═'.repeat(60));
console.log(`Current version: ${versionCheck.current}`);
console.log(`Required version: ${versionCheck.required}`);
console.log('');
console.log('📥 TO FIX THIS ISSUE:');
console.log('');
console.log('1. 🌐 Visit: https://nodejs.org/');
console.log('2. 📦 Download the "LTS" or "Current" version');
console.log('3. 🔧 Install Node.js v22 or higher');
console.log('4. 🔄 Restart your terminal');
console.log('5. ✅ Run this command again');
console.log('');
console.log('💡 You can also use a Node.js version manager:');
console.log(' • nvm: https://github.com/nvm-sh/nvm');
console.log(' • fnm: https://github.com/Schniz/fnm');
console.log(' • n: https://github.com/tj/n');
console.log('');
console.log('═'.repeat(60));
console.log('');
}
/**
* Check if Playwright browsers are installed
*/
static async arePlaywrightBrowsersInstalled() {
try {
// Try to get the Playwright browsers directory
const { stdout } = await execAsync('npx playwright --version');
if (!stdout.includes('Version')) {
return false;
}
// Check if browsers are actually installed by trying to launch one
try {
const { chromium } = await Promise.resolve().then(() => __importStar(require('playwright')));
const browser = await chromium.launch({ headless: true });
await browser.close();
return true;
}
catch (error) {
// If we can't launch a browser, browsers aren't installed
return false;
}
}
catch (error) {
return false;
}
}
/**
* Install Playwright browsers
*/
static async installPlaywrightBrowsers() {
if (this.isInstalling) {
console.log('⏳ Playwright installation already in progress...');
return this.waitForInstallation();
}
if (this.installationComplete) {
console.log('✅ Playwright browsers already installed');
return;
}
this.isInstalling = true;
try {
console.log('📦 Playwright browsers not found. Installing...');
console.log(' This may take a few minutes on first run.');
console.log('');
// Install Playwright browsers
const { stdout, stderr } = await execAsync('npx playwright install', {
maxBuffer: 1024 * 1024 * 10 // 10MB buffer for large output
});
if (stderr && !stderr.includes('Downloading')) {
console.warn('Installation warnings:', stderr);
}
console.log('✅ Playwright browsers installed successfully!');
this.installationComplete = true;
}
catch (error) {
console.error('❌ Failed to install Playwright browsers:', error.message);
throw new Error(`Playwright installation failed: ${error.message}`);
}
finally {
this.isInstalling = false;
}
}
/**
* Wait for ongoing installation to complete
*/
static async waitForInstallation() {
while (this.isInstalling) {
await new Promise(resolve => setTimeout(resolve, 1000));
}
}
/**
* Check and install Playwright browsers if needed
*/
static async ensurePlaywrightBrowsers() {
// First check Node.js version
const nodeCheck = this.checkNodeVersion();
if (!nodeCheck.valid) {
this.displayNodeVersionError();
throw new Error(`Node.js ${nodeCheck.required} is required, but ${nodeCheck.current} is installed`);
}
console.log('🔍 Checking Playwright browser installation...');
const browsersInstalled = await this.arePlaywrightBrowsersInstalled();
if (browsersInstalled) {
console.log('✅ Playwright browsers are installed and ready');
this.installationComplete = true;
return;
}
console.log('📥 Playwright browsers not detected');
await this.installPlaywrightBrowsers();
}
/**
* Get system requirements info
*/
static async getSystemInfo() {
try {
const nodeVersion = process.version;
let playwrightVersion = null;
try {
const { stdout } = await execAsync('npx playwright --version');
const match = stdout.match(/Version (\d+\.\d+\.\d+)/);
playwrightVersion = match ? match[1] : null;
}
catch {
playwrightVersion = null;
}
const browsersInstalled = await this.arePlaywrightBrowsersInstalled();
return {
nodeVersion,
playwrightVersion,
browsersInstalled
};
}
catch (error) {
throw new Error(`Failed to get system info: ${error}`);
}
}
/**
* Display system requirements and installation status
*/
static async displaySystemStatus() {
try {
const info = await this.getSystemInfo();
const nodeCheck = this.checkNodeVersion();
console.log('');
console.log('🖥️ SYSTEM STATUS');
console.log('─'.repeat(50));
console.log(`Node.js: ${info.nodeVersion} ${nodeCheck.valid ? '✅' : '❌'}`);
console.log(`Playwright: ${info.playwrightVersion || 'Not detected'}`);
console.log(`Browsers: ${info.browsersInstalled ? '✅ Installed' : '❌ Not installed'}`);
console.log('');
}
catch (error) {
console.warn('Could not display system status:', error);
}
}
}
exports.PlaywrightInstaller = PlaywrightInstaller;
PlaywrightInstaller.isInstalling = false;
PlaywrightInstaller.installationComplete = false;
PlaywrightInstaller.REQUIRED_NODE_VERSION = 22;
//# sourceMappingURL=PlaywrightInstaller.js.map