UNPKG

n8n-nodes-playwright-mcp

Version:

Complete n8n Playwright node with all Microsoft Playwright MCP tools and AI assistant support for advanced browser automation

75 lines 3.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.installBrowser = installBrowser; const fs_1 = require("fs"); const path_1 = require("path"); const child_process_1 = require("child_process"); const os_1 = require("os"); async function setupBrowsers() { try { console.log('Current working directory:', process.cwd()); console.log('Operating System:', (0, os_1.platform)()); console.log('Node version:', process.version); const os = (0, os_1.platform)(); const sourcePath = os === 'win32' ? (0, path_1.join)(process.env.USERPROFILE || '', 'AppData', 'Local', 'ms-playwright') : (0, path_1.join)(process.env.HOME || '', '.cache', 'ms-playwright'); const browsersPath = (0, path_1.join)(__dirname, '..', 'browsers'); console.log('\nPaths:'); console.log('Source path:', sourcePath); console.log('Destination path:', browsersPath); if (!(0, fs_1.existsSync)(sourcePath)) { console.log('\nInstalling Playwright browsers...'); (0, child_process_1.execSync)('npx --yes playwright install', { stdio: 'inherit' }); } if ((0, fs_1.existsSync)(browsersPath)) { console.log('\nCleaning existing browsers directory...'); (0, fs_1.rmSync)(browsersPath, { recursive: true, force: true }); } console.log('Creating browsers directory...'); (0, fs_1.mkdirSync)(browsersPath, { recursive: true }); console.log('\nCopying browser files...'); const files = (0, fs_1.readdirSync)(sourcePath); for (const file of files) { if (file.startsWith('chromium-') || file.startsWith('firefox-') || file.startsWith('webkit')) { const sourceFull = (0, path_1.join)(sourcePath, file); const destFull = (0, path_1.join)(browsersPath, file); console.log(`Copying ${file}...`); (0, fs_1.cpSync)(sourceFull, destFull, { recursive: true }); } } console.log('\nVerifying installation...'); const installedFiles = (0, fs_1.readdirSync)(browsersPath); console.log('Installed browsers:', installedFiles); const browsers = ['chromium', 'firefox', 'webkit']; for (const browserType of browsers) { const browserDir = installedFiles.find(f => f.startsWith(browserType)); if (!browserDir) { console.log(`\nInstalling ${browserType}...`); await installBrowser(browserType); } } console.log('\nBrowser setup completed successfully!'); } catch (error) { console.error('\nError during browser setup:', error); process.exit(1); } } async function installBrowser(browserType) { try { console.log(`Installing ${browserType}...`); (0, child_process_1.execSync)(`PLAYWRIGHT_BROWSERS_PATH=~/.n8n/nodes/node_modules/n8n-nodes-playwright/dist/nodes/browsers npx --yes playwright install ${browserType}`, { stdio: 'inherit' }); } catch (error) { console.error(`Failed to install ${browserType}:`, error); } } console.log('Starting browser setup...\n'); setupBrowsers().catch(error => { console.error('Unhandled error:', error); process.exit(1); }); //# sourceMappingURL=setup-browsers.js.map