sessionsnap 0.0.1 → 0.0.2

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.
@@ -19,16 +19,17 @@ program
19
19
  .requiredOption('--profile <name>', 'Profile name to save the session under')
20
20
  .option('--out <file>', 'Custom output path for the snapshot JSON')
21
21
  .option('--wait <minutes>', 'Max minutes to wait for login', parseFloat)
22
+ .option('--target <pattern>', 'Regex pattern to wait for in URL (e.g., "/dashboard" or "^https://.*/app")')
22
23
  .option('--record', 'Record user actions (clicks, inputs, navigations)')
23
24
  .action(async (url, opts) => {
24
25
  validateRunner(opts.runner);
25
26
  try {
26
27
  if (opts.runner === 'puppeteer') {
27
28
  const { capture } = await import('../src/puppeteer/capture.js');
28
- await capture(url, { profile: opts.profile, out: opts.out, waitMinutes: opts.wait, record: opts.record });
29
+ await capture(url, { profile: opts.profile, out: opts.out, waitMinutes: opts.wait, targetPattern: opts.target, record: opts.record });
29
30
  } else {
30
31
  const { capture } = await import('../src/playwright/capture.js');
31
- await capture(url, { profile: opts.profile, out: opts.out, waitMinutes: opts.wait, record: opts.record });
32
+ await capture(url, { profile: opts.profile, out: opts.out, waitMinutes: opts.wait, targetPattern: opts.target, record: opts.record });
32
33
  }
33
34
  } catch (err) {
34
35
  console.error(`[sessionsnap] Error: ${err.message}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sessionsnap",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Capture and reuse authenticated browser sessions (Puppeteer + Playwright)",
5
5
  "type": "module",
6
6
  "bin": {
@@ -18,10 +18,22 @@ export async function getCookieCount(page, runner) {
18
18
  return cookies.length;
19
19
  }
20
20
 
21
- export async function waitForLoginComplete(page, { runner, waitMinutes } = {}) {
21
+ export async function waitForLoginComplete(page, { runner, waitMinutes, targetPattern } = {}) {
22
22
  const timeout = (waitMinutes ?? DEFAULT_TIMEOUT_MIN) * 60 * 1000;
23
23
  const start = Date.now();
24
24
  const initialCookieCount = await getCookieCount(page, runner);
25
+
26
+ // Compile target pattern if provided
27
+ let targetRegex = null;
28
+ if (targetPattern) {
29
+ try {
30
+ targetRegex = new RegExp(targetPattern);
31
+ console.log(`[sessionsnap] Waiting for URL matching pattern: ${targetPattern}`);
32
+ } catch (err) {
33
+ console.error(`[sessionsnap] Invalid regex pattern: ${targetPattern}. Error: ${err.message}`);
34
+ throw new Error(`Invalid target pattern: ${targetPattern}`);
35
+ }
36
+ }
25
37
 
26
38
  return new Promise((resolve) => {
27
39
  const timer = setInterval(async () => {
@@ -36,6 +48,20 @@ export async function waitForLoginComplete(page, { runner, waitMinutes } = {}) {
36
48
  }
37
49
 
38
50
  const currentUrl = page.url();
51
+
52
+ // If target pattern is provided, check if URL matches
53
+ if (targetRegex) {
54
+ if (targetRegex.test(currentUrl)) {
55
+ clearInterval(timer);
56
+ console.log(`[sessionsnap] Target URL pattern matched: ${currentUrl}`);
57
+ resolve(true);
58
+ return;
59
+ }
60
+ // Continue waiting if pattern doesn't match yet
61
+ return;
62
+ }
63
+
64
+ // Default behavior: check URL and cookie heuristics
39
65
  const urlClear = !isLoginUrl(currentUrl);
40
66
 
41
67
  let cookieIncreased = false;
@@ -3,7 +3,7 @@ import { waitForLoginComplete } from '../core/heuristics.js';
3
3
  import { createSnapshot, normalizePlaywrightState } from '../core/snapshot.js';
4
4
  import { setupRecorder } from '../core/recorder.js';
5
5
 
6
- export async function capture(url, { profile, out, waitMinutes, record }) {
6
+ export async function capture(url, { profile, out, waitMinutes, targetPattern, record }) {
7
7
  const { chromium } = await import('playwright');
8
8
  const userDataDir = await ensureProfileDir(profile);
9
9
 
@@ -24,12 +24,16 @@ export async function capture(url, { profile, out, waitMinutes, record }) {
24
24
  console.log(`[sessionsnap] Navigating to: ${url}`);
25
25
  await page.goto(url, { waitUntil: 'domcontentloaded' });
26
26
 
27
- console.log('[sessionsnap] Please log in manually. Login completion will be detected automatically.');
27
+ if (targetPattern) {
28
+ console.log(`[sessionsnap] Please log in manually. Waiting for URL matching pattern: ${targetPattern}`);
29
+ } else {
30
+ console.log('[sessionsnap] Please log in manually. Login completion will be detected automatically.');
31
+ }
28
32
  if (record) {
29
33
  console.log('[sessionsnap] Recording actions... (press Ctrl+C to stop early)');
30
34
  }
31
35
 
32
- const detected = await waitForLoginComplete(page, { runner: 'playwright', waitMinutes });
36
+ const detected = await waitForLoginComplete(page, { runner: 'playwright', waitMinutes, targetPattern });
33
37
 
34
38
  if (detected) {
35
39
  console.log('[sessionsnap] Login detected! Capturing session...');
@@ -3,7 +3,7 @@ import { waitForLoginComplete } from '../core/heuristics.js';
3
3
  import { createSnapshot, normalizePuppeteerCookies } from '../core/snapshot.js';
4
4
  import { setupRecorder } from '../core/recorder.js';
5
5
 
6
- export async function capture(url, { profile, out, waitMinutes, record }) {
6
+ export async function capture(url, { profile, out, waitMinutes, targetPattern, record }) {
7
7
  const puppeteer = await import('puppeteer');
8
8
  const userDataDir = await ensureProfileDir(profile);
9
9
 
@@ -25,12 +25,16 @@ export async function capture(url, { profile, out, waitMinutes, record }) {
25
25
  console.log(`[sessionsnap] Navigating to: ${url}`);
26
26
  await page.goto(url, { waitUntil: 'domcontentloaded' });
27
27
 
28
- console.log('[sessionsnap] Please log in manually. Login completion will be detected automatically.');
28
+ if (targetPattern) {
29
+ console.log(`[sessionsnap] Please log in manually. Waiting for URL matching pattern: ${targetPattern}`);
30
+ } else {
31
+ console.log('[sessionsnap] Please log in manually. Login completion will be detected automatically.');
32
+ }
29
33
  if (record) {
30
34
  console.log('[sessionsnap] Recording actions... (press Ctrl+C to stop early)');
31
35
  }
32
36
 
33
- const detected = await waitForLoginComplete(page, { runner: 'puppeteer', waitMinutes });
37
+ const detected = await waitForLoginComplete(page, { runner: 'puppeteer', waitMinutes, targetPattern });
34
38
 
35
39
  if (detected) {
36
40
  console.log('[sessionsnap] Login detected! Capturing session...');