autokap 1.3.29 → 1.3.31

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/dist/browser.js CHANGED
@@ -1042,10 +1042,20 @@ export class Browser {
1042
1042
  });
1043
1043
  instance.browser = instance.context.browser();
1044
1044
  instance.persistentContext = true;
1045
- for (const page of instance.context.pages()) {
1046
- await page.close().catch(() => undefined);
1045
+ // launchPersistentContext opens an initial about:blank page automatically.
1046
+ // Reuse it instead of closing it + opening a new one: Chromium's --kiosk
1047
+ // mode blocks `Target.createTarget` (one-window-only enforcement), so
1048
+ // `context.newPage()` would fail with "Failed to open a new tab" — which
1049
+ // is exactly what bricked 1.3.29. The init scripts registered below run
1050
+ // on the next navigation regardless of when the page was created.
1051
+ const existingPages = instance.context.pages();
1052
+ instance.page = existingPages[0] ?? await instance.context.newPage();
1053
+ // Defensive: close any extra pages Chromium might have opened (unlikely
1054
+ // under --kiosk but cheap insurance). Keep index 0.
1055
+ for (let i = 1; i < existingPages.length; i++) {
1056
+ await existingPages[i].close().catch(() => undefined);
1047
1057
  }
1048
- logger.info(`[capture] Cloud clip capture: persistent Chromium profile seeded at ${cloudChromiumProfileDir}`);
1058
+ logger.info(`[capture] Cloud clip capture: persistent Chromium profile seeded at ${cloudChromiumProfileDir} (reusing initial page, kiosk blocks Target.createTarget)`);
1049
1059
  }
1050
1060
  else {
1051
1061
  // Non-cloud clip capture keeps the regular browser + incognito context
@@ -1098,7 +1108,12 @@ export class Browser {
1098
1108
  document.addEventListener('DOMContentLoaded', install, { once: true });
1099
1109
  }
1100
1110
  }, { styleId: CAPTURE_HIDE_STYLE_ID, css: getCaptureHideCSS() });
1101
- instance.page = await instance.context.newPage();
1111
+ // Persistent context (cloud) already set instance.page by reusing the
1112
+ // initial page launchPersistentContext opened. Only call newPage() for
1113
+ // the regular browser+context path (Mac/Win/local Linux).
1114
+ if (!instance.page) {
1115
+ instance.page = await instance.context.newPage();
1116
+ }
1102
1117
  // Cloud Run only: force the page window to fullscreen via CDP. The
1103
1118
  // --kiosk launch flag is silently ignored by Chromium for windows
1104
1119
  // created by Playwright via Target.createTarget (CDP) — kiosk only
@@ -497,7 +497,15 @@ export class WebPlaywrightLocal {
497
497
  const ffmpegResult = await this.recording.ffmpegRecorder.stop();
498
498
  logger.info(`[capture] Clip ffmpeg+nvenc capture: ${(ffmpegResult.durationMs / 1000).toFixed(2)}s wall, ` +
499
499
  `trim ${Math.round(ffmpegResult.trimStartMs)}ms, output ${ffmpegResult.outputPath}`);
500
- await this.browser.closeContext();
500
+ // Persistent context (cloud) — DO NOT closeContext here. Closing the
501
+ // persistent context tears down the underlying browser process, which
502
+ // breaks the END_CLIP opcode handler's `adapter.getCurrentUrl()` call
503
+ // that runs immediately after this returns (and any subsequent
504
+ // NAVIGATE/CLICK/BEGIN_CLIP opcodes in the same preset). The CDP
505
+ // screencast path (non-ffmpeg branch below) closes context here to
506
+ // release the loop's CDP session — that's not needed for x11grab,
507
+ // ffmpeg has already finalized the MP4. Browser cleanup happens in
508
+ // Browser.close() at end of session.
501
509
  this.recording.finalized = true;
502
510
  this.recording.ffmpegResult = ffmpegResult;
503
511
  this.recording.sourcePath = ffmpegResult.outputPath;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autokap",
3
- "version": "1.3.29",
3
+ "version": "1.3.31",
4
4
  "description": "AI-powered CLI tool for capturing clean screenshots of websites",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",