@mearl/client 2.9.5 → 2.9.6
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/socket.js +14 -7
- package/package.json +2 -2
package/dist/socket.js
CHANGED
|
@@ -89,18 +89,20 @@ function selectBrowserResult(data) {
|
|
|
89
89
|
let spawnAttempted = false;
|
|
90
90
|
/**
|
|
91
91
|
* Attempt to spawn `mearl-native-host` in the background (detached).
|
|
92
|
-
*
|
|
92
|
+
* Browser discovery hosts probe the default local CDP endpoint for browser_list and only
|
|
93
|
+
* persist when a real browser is available.
|
|
93
94
|
* Returns true if a spawn was attempted (regardless of success).
|
|
94
95
|
*/
|
|
95
|
-
async function trySpawnNativeHost(
|
|
96
|
-
|
|
96
|
+
async function trySpawnNativeHost(mode = 'control', retryPreviousAttempt = false) {
|
|
97
|
+
const persistent = mode === 'control';
|
|
98
|
+
if (persistent && spawnAttempted && !retryPreviousAttempt)
|
|
97
99
|
return false;
|
|
98
|
-
if (
|
|
100
|
+
if (persistent)
|
|
99
101
|
spawnAttempted = true;
|
|
100
102
|
try {
|
|
101
103
|
const { spawn } = await import('node:child_process');
|
|
102
104
|
return await new Promise(resolve => {
|
|
103
|
-
const args =
|
|
105
|
+
const args = persistent ? ['--daemon'] : ['--daemon', '--discover-cdp'];
|
|
104
106
|
const child = spawn('mearl-native-host', args, {
|
|
105
107
|
detached: true,
|
|
106
108
|
stdio: 'ignore',
|
|
@@ -216,10 +218,15 @@ async function invokeViaLegacy(action, data, timeoutSec, transport, controlSourc
|
|
|
216
218
|
const err = error;
|
|
217
219
|
const shouldAttemptSpawn = err.code === 'ENOENT' || (action === 'browser_release' && err.code === 'ECONNREFUSED');
|
|
218
220
|
if (shouldAttemptSpawn && !isRetry) {
|
|
219
|
-
const spawned = await trySpawnNativeHost(action
|
|
221
|
+
const spawned = await trySpawnNativeHost(action === 'browser_list' ? 'discovery' : 'control', action === 'browser_release');
|
|
220
222
|
if (spawned) {
|
|
221
|
-
// Wait for the native host to start listening
|
|
223
|
+
// Wait for the native host to start listening. Discovery retries the legacy socket directly
|
|
224
|
+
// so the spawned host receives the probe even if another browser registers in the meantime.
|
|
222
225
|
await new Promise(r => setTimeout(r, 1200));
|
|
226
|
+
if (action === 'browser_list') {
|
|
227
|
+
return invokeViaLegacy(action, data, timeoutSec, transport, controlSource,
|
|
228
|
+
/* isRetry */ true);
|
|
229
|
+
}
|
|
223
230
|
const browsers = listLiveBrowsers();
|
|
224
231
|
if (browsers.length > 0) {
|
|
225
232
|
return invokeOnce(action, data, timeoutSec, transport, browsers[0].socketPath, controlSource);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mearl/client",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.6",
|
|
4
4
|
"description": "Unified Mearl SDK & CLI for local and remote browsers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"commander": "^15.0.0",
|
|
56
56
|
"fastest-levenshtein": "^1.0.16",
|
|
57
57
|
"ws": "^8.18.0",
|
|
58
|
-
"@mearl/cloud-types": "2.9.
|
|
58
|
+
"@mearl/cloud-types": "2.9.6"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/node": "^24.9.1",
|