nothing-browser 0.0.20 → 0.0.21

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.
@@ -740,6 +740,19 @@ var BINARY_NAMES = {
740
740
  };
741
741
  function detectBinary(mode = "headless") {
742
742
  const cwd = process.cwd();
743
+ if (mode !== "headless" && mode !== "headful") {
744
+ if (existsSync(mode)) {
745
+ logger_default.success(`Binary found (custom path): ${mode}`);
746
+ return mode;
747
+ }
748
+ const abs = join(cwd, mode);
749
+ if (existsSync(abs)) {
750
+ logger_default.success(`Binary found (custom path): ${abs}`);
751
+ return abs;
752
+ }
753
+ logger_default.error(`Binary not found at custom path: ${mode}`);
754
+ return null;
755
+ }
743
756
  const name = BINARY_NAMES[mode];
744
757
  if (process.platform === "win32") {
745
758
  const p2 = join(cwd, `${name}.exe`);
@@ -745,6 +745,19 @@ var BINARY_NAMES = {
745
745
  };
746
746
  function detectBinary(mode = "headless") {
747
747
  const cwd = process.cwd();
748
+ if (mode !== "headless" && mode !== "headful") {
749
+ if (existsSync(mode)) {
750
+ logger_default.success(`Binary found (custom path): ${mode}`);
751
+ return mode;
752
+ }
753
+ const abs = join(cwd, mode);
754
+ if (existsSync(abs)) {
755
+ logger_default.success(`Binary found (custom path): ${abs}`);
756
+ return abs;
757
+ }
758
+ logger_default.error(`Binary not found at custom path: ${mode}`);
759
+ return null;
760
+ }
748
761
  const name = BINARY_NAMES[mode];
749
762
  if (process.platform === "win32") {
750
763
  const p2 = join(cwd, `${name}.exe`);
@@ -1,3 +1,3 @@
1
- export type BinaryMode = 'headless' | 'headful';
1
+ export type BinaryMode = 'headless' | 'headful' | (string & {});
2
2
  export declare function detectBinary(mode?: BinaryMode): string | null;
3
3
  //# sourceMappingURL=detect.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../../../piggy/launch/detect.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,SAAS,CAAC;AAOhD,wBAAgB,YAAY,CAAC,IAAI,GAAE,UAAuB,GAAG,MAAM,GAAG,IAAI,CA+BzE"}
1
+ {"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../../../piggy/launch/detect.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,SAAS,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;AAOhE,wBAAgB,YAAY,CAAC,IAAI,GAAE,UAAuB,GAAG,MAAM,GAAG,IAAI,CAgDzE"}
@@ -1 +1 @@
1
- {"version":3,"file":"spawn.d.ts","sourceRoot":"","sources":["../../../piggy/launch/spawn.ts"],"names":[],"mappings":"AAIA,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AASzD,wBAAgB,eAAe,IAAI,IAAI,CAiBtC;AAED,wBAAsB,YAAY,CAAC,IAAI,GAAE,UAAuB,GAAG,OAAO,CAAC,MAAM,CAAC,CAqEjF;AAED,wBAAsB,oBAAoB,CACxC,UAAU,EAAE,MAAM,EAClB,IAAI,GAAE,UAAuB,GAC5B,OAAO,CAAC,IAAI,CAAC,CAqCf;AAED,wBAAgB,WAAW,IAAI,IAAI,CAmBlC"}
1
+ {"version":3,"file":"spawn.d.ts","sourceRoot":"","sources":["../../../piggy/launch/spawn.ts"],"names":[],"mappings":"AAGA,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAQzD,wBAAgB,eAAe,IAAI,IAAI,CAgBtC;AAED,wBAAsB,YAAY,CAAC,IAAI,GAAE,UAAuB,GAAG,OAAO,CAAC,MAAM,CAAC,CAmEjF;AAED,wBAAsB,oBAAoB,CACxC,UAAU,EAAE,MAAM,EAClB,IAAI,GAAE,UAAuB,GAC5B,OAAO,CAAC,IAAI,CAAC,CAmCf;AAED,wBAAgB,WAAW,IAAI,IAAI,CAmBlC"}
package/dist/piggy.js CHANGED
@@ -6871,6 +6871,19 @@ var BINARY_NAMES = {
6871
6871
  };
6872
6872
  function detectBinary(mode = "headless") {
6873
6873
  const cwd = process.cwd();
6874
+ if (mode !== "headless" && mode !== "headful") {
6875
+ if (existsSync(mode)) {
6876
+ logger_default.success(`Binary found (custom path): ${mode}`);
6877
+ return mode;
6878
+ }
6879
+ const abs = join(cwd, mode);
6880
+ if (existsSync(abs)) {
6881
+ logger_default.success(`Binary found (custom path): ${abs}`);
6882
+ return abs;
6883
+ }
6884
+ logger_default.error(`Binary not found at custom path: ${mode}`);
6885
+ return null;
6886
+ }
6874
6887
  const name = BINARY_NAMES[mode];
6875
6888
  if (process.platform === "win32") {
6876
6889
  const p2 = join(cwd, `${name}.exe`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nothing-browser",
3
- "version": "0.0.20",
3
+ "version": "0.0.21",
4
4
  "description": "Browser automation library powered by Nothing Browser",
5
5
  "homepage": "https://github.com/ernest-tech-house-co-operation/nothing-browser#readme",
6
6
  "repository": {
@@ -2,15 +2,32 @@ import { existsSync } from 'fs';
2
2
  import { join } from 'path';
3
3
  import logger from '../logger';
4
4
 
5
- export type BinaryMode = 'headless' | 'headful';
5
+ export type BinaryMode = 'headless' | 'headful' | (string & {});
6
6
 
7
- const BINARY_NAMES: Record<BinaryMode, string> = {
7
+ const BINARY_NAMES: Record<string, string> = {
8
8
  headless: 'nothing-browser-headless',
9
9
  headful: 'nothing-browser-headful',
10
10
  };
11
11
 
12
12
  export function detectBinary(mode: BinaryMode = 'headless'): string | null {
13
13
  const cwd = process.cwd();
14
+
15
+ // Custom path passed directly
16
+ if (mode !== 'headless' && mode !== 'headful') {
17
+ if (existsSync(mode)) {
18
+ logger.success(`Binary found (custom path): ${mode}`);
19
+ return mode;
20
+ }
21
+ // try relative to cwd
22
+ const abs = join(cwd, mode);
23
+ if (existsSync(abs)) {
24
+ logger.success(`Binary found (custom path): ${abs}`);
25
+ return abs;
26
+ }
27
+ logger.error(`Binary not found at custom path: ${mode}`);
28
+ return null;
29
+ }
30
+
14
31
  const name = BINARY_NAMES[mode];
15
32
 
16
33
  // Windows
@@ -1,4 +1,3 @@
1
- // piggy/launch/spawn.ts
2
1
  import { spawn as nodeSpawn } from "child_process";
3
2
  import { execSync } from "child_process";
4
3
  import { platform } from "os";
@@ -8,13 +7,11 @@ import logger from "../logger";
8
7
  let activeProcess: any = null;
9
8
  const extraProcesses: any[] = [];
10
9
 
11
- // Runtime detection without importing "bun" at build time
12
10
  const isBun = typeof (globalThis as any).Bun !== 'undefined';
13
11
 
14
12
  export function killAllBrowsers(): void {
15
13
  try {
16
14
  logger.info('Cleaning up existing browser processes...');
17
-
18
15
  if (platform() === 'win32') {
19
16
  execSync('taskkill /F /IM nothing-browser-headless.exe 2>nul || true', { stdio: 'ignore' });
20
17
  execSync('taskkill /F /IM nothing-browser-headful.exe 2>nul || true', { stdio: 'ignore' });
@@ -42,7 +39,6 @@ export async function spawnBrowser(mode: BinaryMode = 'headless'): Promise<strin
42
39
  logger.info(`Spawning Nothing Browser (${mode}) from: ${binaryPath}`);
43
40
 
44
41
  if (isBun) {
45
- // Bun runtime - use Bun.spawn
46
42
  const Bun = (globalThis as any).Bun;
47
43
  activeProcess = Bun.spawn([binaryPath], {
48
44
  stdio: ['ignore', 'pipe', 'pipe'],
@@ -66,7 +62,6 @@ export async function spawnBrowser(mode: BinaryMode = 'headless'): Promise<strin
66
62
  activeProcess = null;
67
63
  });
68
64
  } else {
69
- // Node.js runtime
70
65
  activeProcess = nodeSpawn(binaryPath, [], {
71
66
  stdio: ['ignore', 'pipe', 'pipe'],
72
67
  env: process.env,
@@ -113,7 +108,6 @@ export async function spawnBrowserOnSocket(
113
108
  logger.info(`Spawning browser (${mode}) on socket: ${socketName}`);
114
109
 
115
110
  if (isBun) {
116
- // Bun runtime
117
111
  const Bun = (globalThis as any).Bun;
118
112
  const proc = Bun.spawn([binaryPath], {
119
113
  stdio: ['ignore', 'pipe', 'pipe'],
@@ -126,7 +120,6 @@ export async function spawnBrowserOnSocket(
126
120
  logger.warn(`Browser on socket ${socketName} exited with code: ${code}`);
127
121
  });
128
122
  } else {
129
- // Node.js runtime
130
123
  const proc = nodeSpawn(binaryPath, [], {
131
124
  stdio: ['ignore', 'pipe', 'pipe'],
132
125
  env: { ...process.env, PIGGY_SOCKET: socketName },
@@ -153,7 +146,7 @@ export function killBrowser(): void {
153
146
  }
154
147
  activeProcess = null;
155
148
  }
156
-
149
+
157
150
  for (const proc of extraProcesses) {
158
151
  if (isBun) {
159
152
  proc.kill();