capiumbrowser 1.1.2 → 1.1.4

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/lib/download.js CHANGED
@@ -106,6 +106,17 @@ function destRoot() {
106
106
  return process.env.CAPIUM_HOME || path.join(os.homedir(), '.capium');
107
107
  }
108
108
 
109
+ /**
110
+ * True if `binPath` lives under the canonical install root (~/.capium or CAPIUM_HOME). A
111
+ * same-version binary found OUTSIDE it (a legacy install elsewhere) is NOT reused -- we reinstall
112
+ * into the root so everything lands under one folder next to the license.
113
+ */
114
+ function inRoot(binPath, root) {
115
+ const d = path.resolve(path.dirname(binPath));
116
+ const r = path.resolve(root);
117
+ return d === r || d.startsWith(r + path.sep);
118
+ }
119
+
109
120
  /**
110
121
  * Extract a distro archive, sniffing gzip/zip/tar so the server can ship any of them.
111
122
  *
@@ -334,12 +345,13 @@ async function ensureBinary({ version = null, licenseKey = null, server = null }
334
345
  else revision = binaryRevisionFor(tag);
335
346
  const bid = buildId(version, revision);
336
347
 
337
- // Reuse the cached binary ONLY if it's already this exact build (version + revision). A
338
- // different build -- e.g. after `npm install capiumbrowser@latest` bumps this OS's pinned build
339
- // or re-spin -- falls through to fetch the new one and drop the old.
348
+ // Reuse the cached binary ONLY if it's already this exact build (version + revision) AND it
349
+ // lives in the canonical root (~/.capium or CAPIUM_HOME). A different build -- or a same-build
350
+ // binary in a LEGACY location -- falls through so we (re)install into ~/.capium, keeping the
351
+ // browser under one folder next to the license.
340
352
  try {
341
353
  const existing = config.findBinary();
342
- if (readInstalledVersion(existing) === bid) return existing;
354
+ if (readInstalledVersion(existing) === bid && inRoot(existing, destRoot())) return existing;
343
355
  } catch {}
344
356
 
345
357
  let url;
@@ -407,6 +419,7 @@ module.exports = {
407
419
  downloadTag,
408
420
  distroPath,
409
421
  destRoot,
422
+ inRoot,
410
423
  ensureBinary,
411
424
  installedVersion,
412
425
  expectedBuildId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capiumbrowser",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "Drop-in stealth browser SDK on top of Playwright or Puppeteer (Capium Chromium).",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Capzy (https://capzy.ai)",
package/playwright.js CHANGED
@@ -20,6 +20,7 @@
20
20
  */
21
21
  'use strict';
22
22
 
23
+ const path = require('path');
23
24
  const config = require('./lib/config');
24
25
  const download = require('./lib/download');
25
26
  const human = require('./lib/human');
@@ -50,11 +51,19 @@ async function resolveBinary(binary, licenseKey) {
50
51
  const want = download.expectedBuildId();
51
52
  try {
52
53
  const found = config.findBinary();
54
+ if (want === null) return found; // can't determine target (unsupported/manifest) -- trust it
53
55
  const have = download.installedVersion(found);
54
- if (want === null || have === want) return found;
55
- process.stderr.write(
56
- `capium: ignoring stale binary at ${found} (build ${have}; current target ${want}) and ` +
57
- `fetching the current build. Delete it or set CAPIUM_BINARY to silence this.\n`);
56
+ const atRoot = download.inRoot(found, download.destRoot());
57
+ if (have === want && atRoot) return found;
58
+ if (have === want && !atRoot) {
59
+ process.stderr.write(
60
+ `capium: moving the browser out of ${path.dirname(found)} into ~/.capium (the shared ` +
61
+ `capium home). Set CAPIUM_BINARY to pin a location.\n`);
62
+ } else {
63
+ process.stderr.write(
64
+ `capium: ignoring stale binary at ${found} (build ${have}; current target ${want}) and ` +
65
+ `fetching the current build. Delete it or set CAPIUM_BINARY to silence this.\n`);
66
+ }
58
67
  } catch (e) {
59
68
  if (e.code !== 'ENOENT') throw e;
60
69
  }
package/puppeteer.js CHANGED
@@ -24,6 +24,7 @@
24
24
  */
25
25
  'use strict';
26
26
 
27
+ const path = require('path');
27
28
  const config = require('./lib/config');
28
29
  const download = require('./lib/download');
29
30
  const human = require('./lib/human');
@@ -53,11 +54,19 @@ async function resolveBinary(binary, licenseKey) {
53
54
  const want = download.expectedBuildId();
54
55
  try {
55
56
  const found = config.findBinary();
57
+ if (want === null) return found; // can't determine target (unsupported/manifest) -- trust it
56
58
  const have = download.installedVersion(found);
57
- if (want === null || have === want) return found;
58
- process.stderr.write(
59
- `capium: ignoring stale binary at ${found} (build ${have}; current target ${want}) and ` +
60
- `fetching the current build. Delete it or set CAPIUM_BINARY to silence this.\n`);
59
+ const atRoot = download.inRoot(found, download.destRoot());
60
+ if (have === want && atRoot) return found;
61
+ if (have === want && !atRoot) {
62
+ process.stderr.write(
63
+ `capium: moving the browser out of ${path.dirname(found)} into ~/.capium (the shared ` +
64
+ `capium home). Set CAPIUM_BINARY to pin a location.\n`);
65
+ } else {
66
+ process.stderr.write(
67
+ `capium: ignoring stale binary at ${found} (build ${have}; current target ${want}) and ` +
68
+ `fetching the current build. Delete it or set CAPIUM_BINARY to silence this.\n`);
69
+ }
61
70
  } catch (e) {
62
71
  if (e.code !== 'ENOENT') throw e;
63
72
  }