-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
executable file
·54 lines (44 loc) · 1.72 KB
/
setup.js
File metadata and controls
executable file
·54 lines (44 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env bun
const { chromium } = require('playwright');
const fs = require('fs');
const { PROFILE_PATH, BROWSER_PATH } = require('./lib/constants');
const { stopAndWait } = require('./lib/client');
async function setup() {
console.log('\n🔧 \x1b[1mGoogle Search CLI Setup\x1b[0m\n');
// Stop any running daemon so the profile isn't locked
try {
console.log('⚠️ Stopping running daemon...');
await stopAndWait();
console.log(' Daemon stopped.\n');
} catch {
console.log(' No daemon running.\n');
}
if (fs.existsSync(PROFILE_PATH)) {
console.log('🧹 Clearing previous profile...');
fs.rmSync(PROFILE_PATH, { recursive: true, force: true });
}
fs.mkdirSync(PROFILE_PATH, { recursive: true });
console.log('1. A browser window will open.');
console.log('2. Log in to your Google Account.');
console.log('3. Complete any CAPTCHAs if prompted.');
console.log('4. \x1b[33mClose the browser window when done.\x1b[0m\n');
try {
const context = await chromium.launchPersistentContext(PROFILE_PATH, {
executablePath: BROWSER_PATH,
headless: false,
args: ['--no-sandbox', '--disable-blink-features=AutomationControlled'],
viewport: { width: 1280, height: 800 }
});
const page = await context.newPage();
await page.goto('https://www.google.com/search?q=test');
await new Promise(resolve => context.on('close', resolve));
console.log('\n✅ \x1b[32mSetup complete!\x1b[0m');
console.log('Run: \x1b[36mask "your query"\x1b[0m\n');
} catch (err) {
console.error('\n❌ Error:', err.message);
if (err.message.includes('SingletonLock')) {
console.error(' Close all Chrome instances first, or run: ask --stop');
}
}
}
setup();