playwright-repl 0.2.1 → 0.7.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/resolve.mjs DELETED
@@ -1,82 +0,0 @@
1
- /**
2
- * Shared dependencies and command vocabulary.
3
- * No @playwright/cli — we start the daemon ourselves via daemon-launcher.cjs.
4
- */
5
-
6
- import fs from 'node:fs';
7
- import { fileURLToPath } from 'node:url';
8
- import { createRequire } from 'node:module';
9
-
10
- const require = createRequire(import.meta.url);
11
-
12
- // ─── Own dependencies ────────────────────────────────────────────────────────
13
-
14
- export const minimist = require('minimist');
15
-
16
- const pkgUrl = new URL('../package.json', import.meta.url);
17
- const pkg = JSON.parse(fs.readFileSync(pkgUrl, 'utf-8'));
18
- export const replVersion = pkg.version;
19
-
20
- // Must match what daemon-launcher.cjs computes via require.resolve('../package.json')
21
- export const packageLocation = fileURLToPath(pkgUrl);
22
-
23
- // ─── Command vocabulary ──────────────────────────────────────────────────────
24
-
25
- export const COMMANDS = {
26
- 'open': { desc: 'Open the browser', options: [] },
27
- 'close': { desc: 'Close the browser', options: [] },
28
- 'goto': { desc: 'Navigate to a URL', options: [] },
29
- 'go-back': { desc: 'Go back', options: [] },
30
- 'go-forward': { desc: 'Go forward', options: [] },
31
- 'reload': { desc: 'Reload page', options: [] },
32
- 'click': { desc: 'Click an element', options: ['--button', '--modifiers'] },
33
- 'dblclick': { desc: 'Double-click', options: ['--button', '--modifiers'] },
34
- 'fill': { desc: 'Fill a form field', options: ['--submit'] },
35
- 'type': { desc: 'Type text key by key', options: ['--submit'] },
36
- 'press': { desc: 'Press a keyboard key', options: [] },
37
- 'hover': { desc: 'Hover over element', options: [] },
38
- 'select': { desc: 'Select dropdown option', options: [] },
39
- 'check': { desc: 'Check a checkbox', options: [] },
40
- 'uncheck': { desc: 'Uncheck a checkbox', options: [] },
41
- 'upload': { desc: 'Upload a file', options: [] },
42
- 'drag': { desc: 'Drag and drop', options: [] },
43
- 'snapshot': { desc: 'Accessibility snapshot', options: ['--filename'] },
44
- 'screenshot': { desc: 'Take a screenshot', options: ['--filename', '--fullPage'] },
45
- 'eval': { desc: 'Evaluate JavaScript', options: [] },
46
- 'console': { desc: 'Console messages', options: ['--clear'] },
47
- 'network': { desc: 'Network requests', options: ['--clear', '--includeStatic'] },
48
- 'run-code': { desc: 'Run Playwright code', options: [] },
49
- 'tab-list': { desc: 'List tabs', options: [] },
50
- 'tab-new': { desc: 'New tab', options: [] },
51
- 'tab-close': { desc: 'Close tab', options: [] },
52
- 'tab-select': { desc: 'Select tab', options: [] },
53
- 'cookie-list': { desc: 'List cookies', options: [] },
54
- 'cookie-get': { desc: 'Get cookie', options: [] },
55
- 'cookie-set': { desc: 'Set cookie', options: [] },
56
- 'cookie-delete': { desc: 'Delete cookie', options: [] },
57
- 'cookie-clear': { desc: 'Clear cookies', options: [] },
58
- 'localstorage-list': { desc: 'List localStorage', options: [] },
59
- 'localstorage-get': { desc: 'Get localStorage', options: [] },
60
- 'localstorage-set': { desc: 'Set localStorage', options: [] },
61
- 'localstorage-delete': { desc: 'Delete localStorage', options: [] },
62
- 'localstorage-clear': { desc: 'Clear localStorage', options: [] },
63
- 'sessionstorage-list': { desc: 'List sessionStorage', options: [] },
64
- 'sessionstorage-get': { desc: 'Get sessionStorage', options: [] },
65
- 'sessionstorage-set': { desc: 'Set sessionStorage', options: [] },
66
- 'sessionstorage-delete':{ desc: 'Delete sessionStorage', options: [] },
67
- 'sessionstorage-clear': { desc: 'Clear sessionStorage', options: [] },
68
- 'state-save': { desc: 'Save storage state', options: ['--filename'] },
69
- 'state-load': { desc: 'Load storage state', options: [] },
70
- 'dialog-accept': { desc: 'Accept dialog', options: [] },
71
- 'dialog-dismiss': { desc: 'Dismiss dialog', options: [] },
72
- 'route': { desc: 'Add network route', options: [] },
73
- 'route-list': { desc: 'List routes', options: [] },
74
- 'unroute': { desc: 'Remove route', options: [] },
75
- 'resize': { desc: 'Resize window', options: [] },
76
- 'pdf': { desc: 'Save as PDF', options: ['--filename'] },
77
- 'config-print': { desc: 'Print config', options: [] },
78
- 'install-browser': { desc: 'Install browser', options: [] },
79
- 'list': { desc: 'List sessions', options: [] },
80
- 'close-all': { desc: 'Close all sessions', options: [] },
81
- 'kill-all': { desc: 'Kill all daemons', options: [] },
82
- };
package/src/workspace.mjs DELETED
@@ -1,104 +0,0 @@
1
- /**
2
- * Workspace detection and daemon lifecycle.
3
- *
4
- * Socket hash: sha1(workspaceDir || packageLocation).substring(0, 16)
5
- * where packageLocation = our package.json (same as daemon-launcher.cjs uses).
6
- */
7
-
8
- import path from 'node:path';
9
- import fs from 'node:fs';
10
- import os from 'node:os';
11
- import net from 'node:net';
12
- import crypto from 'node:crypto';
13
- import { execSync } from 'node:child_process';
14
- import { fileURLToPath } from 'node:url';
15
- import { packageLocation } from './resolve.mjs';
16
-
17
- // ─── Workspace detection ─────────────────────────────────────────────────────
18
-
19
- export function findWorkspaceDir(startDir) {
20
- let dir = startDir;
21
- for (let i = 0; i < 10; i++) {
22
- if (fs.existsSync(path.join(dir, '.playwright'))) return dir;
23
- const parent = path.dirname(dir);
24
- if (parent === dir) break;
25
- dir = parent;
26
- }
27
- return undefined;
28
- }
29
-
30
- // ─── Hash (must match daemon-launcher.cjs → program.js logic) ────────────────
31
-
32
- const workspaceDir = findWorkspaceDir(process.cwd());
33
- const hashInput = workspaceDir || packageLocation;
34
- const workspaceDirHash = crypto.createHash('sha1').update(hashInput).digest('hex').substring(0, 16);
35
-
36
- // ─── Socket path ─────────────────────────────────────────────────────────────
37
-
38
- function socketsBaseDir() {
39
- if (process.platform === 'win32') return null;
40
- return process.env.PLAYWRIGHT_DAEMON_SOCKETS_DIR || path.join(os.tmpdir(), 'playwright-cli');
41
- }
42
-
43
- export function socketPath(sessionName) {
44
- if (process.platform === 'win32')
45
- return `\\\\.\\pipe\\${workspaceDirHash}-${sessionName}.sock`;
46
- return path.join(socketsBaseDir(), workspaceDirHash, `${sessionName}.sock`);
47
- }
48
-
49
- // ─── Daemon profiles dir ─────────────────────────────────────────────────────
50
-
51
- function baseDaemonDir() {
52
- if (process.platform === 'darwin')
53
- return path.join(os.homedir(), 'Library', 'Caches', 'ms-playwright', 'daemon');
54
- if (process.platform === 'win32')
55
- return path.join(process.env.LOCALAPPDATA || path.join(os.homedir(), 'AppData', 'Local'), 'ms-playwright', 'daemon');
56
- return path.join(os.homedir(), '.cache', 'ms-playwright', 'daemon');
57
- }
58
-
59
- export const daemonProfilesDir = path.join(baseDaemonDir(), workspaceDirHash);
60
-
61
- // ─── Daemon lifecycle ────────────────────────────────────────────────────────
62
-
63
- export async function isDaemonRunning(sessionName) {
64
- const sockPath = socketPath(sessionName);
65
- return new Promise((resolve) => {
66
- const sock = net.createConnection(sockPath, () => {
67
- sock.destroy();
68
- resolve(true);
69
- });
70
- sock.on('error', () => resolve(false));
71
- });
72
- }
73
-
74
- /**
75
- * Start daemon using our own launcher (no @playwright/cli needed).
76
- */
77
- export async function startDaemon(sessionName, opts = {}) {
78
- const launcherPath = fileURLToPath(new URL('../bin/daemon-launcher.cjs', import.meta.url));
79
-
80
- const args = [launcherPath];
81
- if (sessionName !== 'default') args.push(`-s=${sessionName}`);
82
- args.push('open');
83
- if (opts.headed) args.push('--headed');
84
- if (opts.browser) args.push('--browser', opts.browser);
85
- if (opts.persistent) args.push('--persistent');
86
- if (opts.profile) args.push('--profile', opts.profile);
87
- if (opts.config) args.push('--config', opts.config);
88
-
89
- if (!opts.silent) console.log(`🚀 Starting daemon...`);
90
-
91
- try {
92
- const output = execSync(`node ${args.map(a => `"${a}"`).join(' ')}`, {
93
- encoding: 'utf-8',
94
- timeout: 30000,
95
- stdio: ['pipe', 'pipe', 'pipe'],
96
- });
97
- if (output.trim()) console.log(output.trim());
98
- } catch (err) {
99
- if (err.stdout?.trim()) console.log(err.stdout.trim());
100
- if (err.stderr?.trim()) console.error(err.stderr.trim());
101
- }
102
- }
103
-
104
- export { workspaceDirHash };