@farmslot/adapter-web 0.19.35 → 0.19.37
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/CHANGELOG.md +8 -0
- package/dist/web-dapp/index.d.mts +20 -0
- package/dist/web-dapp/launch.d.mts +1 -0
- package/dist/web-dapp/lib/runtime.d.mts +1 -1
- package/package.json +3 -3
- package/src/web-dapp/index.mjs +40 -15
- package/src/web-dapp/launch.mjs +50 -11
- package/src/web-dapp/lib/readiness.mjs +6 -2
- package/src/web-dapp/lib/runtime.mjs +26 -11
- package/src/web-dapp/verify.mjs +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,14 @@ All notable changes to `@farmslot/adapter-web` are tracked here.
|
|
|
6
6
|
|
|
7
7
|
- Active-development baseline; add user-facing changes here before release or package publication.
|
|
8
8
|
|
|
9
|
+
## 0.19.37 - 2026-11-30
|
|
10
|
+
|
|
11
|
+
- Without a named account, the web-dapp launch keeps the browser's current account, else the fixture's first one, instead of assuming `dev1`.
|
|
12
|
+
|
|
13
|
+
## 0.19.36 - 2026-11-26
|
|
14
|
+
|
|
15
|
+
- Recover Web DApp launches when the saved browser has lost its app tab or shows an error page, using the existing profile and network protections.
|
|
16
|
+
|
|
9
17
|
## 0.19.35 - 2026-11-25
|
|
10
18
|
|
|
11
19
|
- Uses recipe-runner 0.52.5: `ui.wait_for` on a busy page ends with its own timeout instead of a raw CDP timeout.
|
|
@@ -20,6 +20,26 @@ export function webDappOnlyLaunchFlags(options: Record<string, string | boolean>
|
|
|
20
20
|
* @returns {Record<string, unknown>}
|
|
21
21
|
*/
|
|
22
22
|
export function parseWebDappLauncherOutput(output: string): Record<string, unknown>;
|
|
23
|
+
/**
|
|
24
|
+
* The account the public launch passes: explicit, else TERMINAL_ACCOUNT, else none (current or first fixture account).
|
|
25
|
+
* @param {Record<string, unknown>} [options]
|
|
26
|
+
* @param {NodeJS.ProcessEnv} [env]
|
|
27
|
+
* @returns {string}
|
|
28
|
+
*/
|
|
29
|
+
export function webDappLaunchAccount(options?: Record<string, unknown>, env?: NodeJS.ProcessEnv): string;
|
|
30
|
+
/**
|
|
31
|
+
* The launcher argv the public launch runs (before optional flags).
|
|
32
|
+
* @param {{ target: string, cdpPort: string, appPort: string, options?: Record<string, unknown>, signerModule?: string }} launch
|
|
33
|
+
* @param {NodeJS.ProcessEnv} [env]
|
|
34
|
+
* @returns {string[]}
|
|
35
|
+
*/
|
|
36
|
+
export function webDappLaunchArgv({ target, cdpPort, appPort, options, signerModule }: {
|
|
37
|
+
target: string;
|
|
38
|
+
cdpPort: string;
|
|
39
|
+
appPort: string;
|
|
40
|
+
options?: Record<string, unknown>;
|
|
41
|
+
signerModule?: string;
|
|
42
|
+
}, env?: NodeJS.ProcessEnv): string[];
|
|
23
43
|
export function webDappAppPort(): number | undefined;
|
|
24
44
|
export function webDappCdpPort(): number | undefined;
|
|
25
45
|
/**
|
|
@@ -22,6 +22,7 @@ export function checkFocusAfterLaunch(runtime: any, previous: any, { ourPids, fo
|
|
|
22
22
|
ourPids?: number[] | undefined;
|
|
23
23
|
focus?: any;
|
|
24
24
|
}): any;
|
|
25
|
+
export function hasHealthyAppPage(client: any, appOrigin: any): Promise<boolean>;
|
|
25
26
|
export function backgroundWindowParams(url: any, placement: any): {
|
|
26
27
|
left?: any;
|
|
27
28
|
top?: any;
|
|
@@ -43,7 +43,7 @@ export function resolveAccountAddress(input: any, env?: NodeJS.ProcessEnv): Prom
|
|
|
43
43
|
address: any;
|
|
44
44
|
}>;
|
|
45
45
|
export const SIGNER_MODES: readonly string[];
|
|
46
|
-
export const DEFAULT_ACCOUNT: "
|
|
46
|
+
export const DEFAULT_ACCOUNT: "";
|
|
47
47
|
export const DERIVED_ACCOUNTS_ENV: "RECIPE_WALLET_DERIVED_ACCOUNTS";
|
|
48
48
|
import { POLICY_ENV } from './policy.mjs';
|
|
49
49
|
import { webDappAdapterId } from './policy.mjs';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farmslot/adapter-web",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.37",
|
|
4
4
|
"description": "Web platform adapter for Farmslot recipes: resolve and launch an isolated Chromium, own its CDP port, load unpacked extensions, and keep macOS focus.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"exports": {
|
|
@@ -88,8 +88,8 @@
|
|
|
88
88
|
},
|
|
89
89
|
"dependencies": {
|
|
90
90
|
"@farmslot/adapter-sdk": "0.31.4",
|
|
91
|
-
"@farmslot/protocol": "0.92.
|
|
92
|
-
"@farmslot/recipe-runner": "0.52.
|
|
91
|
+
"@farmslot/protocol": "0.92.6",
|
|
92
|
+
"@farmslot/recipe-runner": "0.52.8",
|
|
93
93
|
"ws": "^8.18.0"
|
|
94
94
|
},
|
|
95
95
|
"devDependencies": {
|
package/src/web-dapp/index.mjs
CHANGED
|
@@ -212,6 +212,44 @@ function portFromEnv(...names) {
|
|
|
212
212
|
return undefined;
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
+
/**
|
|
216
|
+
* The account the public launch passes: explicit, else TERMINAL_ACCOUNT, else none (current or first fixture account).
|
|
217
|
+
* @param {Record<string, unknown>} [options]
|
|
218
|
+
* @param {NodeJS.ProcessEnv} [env]
|
|
219
|
+
* @returns {string}
|
|
220
|
+
*/
|
|
221
|
+
export function webDappLaunchAccount(options = {}, env = process.env) {
|
|
222
|
+
const explicit = typeof options.account === 'string' ? options.account : undefined;
|
|
223
|
+
return explicit ?? env.TERMINAL_ACCOUNT ?? '';
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* The launcher argv the public launch runs (before optional flags).
|
|
228
|
+
* @param {{ target: string, cdpPort: string, appPort: string, options?: Record<string, unknown>, signerModule?: string }} launch
|
|
229
|
+
* @param {NodeJS.ProcessEnv} [env]
|
|
230
|
+
* @returns {string[]}
|
|
231
|
+
*/
|
|
232
|
+
export function webDappLaunchArgv(
|
|
233
|
+
{ target, cdpPort, appPort, options = {}, signerModule },
|
|
234
|
+
env = process.env,
|
|
235
|
+
) {
|
|
236
|
+
const signer = typeof options.signer === 'string' ? options.signer : undefined;
|
|
237
|
+
return [
|
|
238
|
+
webDappLeafPath('launch'),
|
|
239
|
+
'--target',
|
|
240
|
+
target,
|
|
241
|
+
'--cdp-port',
|
|
242
|
+
cdpPort,
|
|
243
|
+
'--app-port',
|
|
244
|
+
appPort,
|
|
245
|
+
'--signer',
|
|
246
|
+
signer ?? env.TERMINAL_SIGNER ?? defaultSigner(signerModule),
|
|
247
|
+
'--account',
|
|
248
|
+
webDappLaunchAccount(options, env),
|
|
249
|
+
'--json',
|
|
250
|
+
];
|
|
251
|
+
}
|
|
252
|
+
|
|
215
253
|
export function webDappAppPort() {
|
|
216
254
|
return portFromEnv('TERMINAL_APP_PORT', 'RECIPE_WATCHER_PORT', 'WATCHER_PORT');
|
|
217
255
|
}
|
|
@@ -486,20 +524,7 @@ export function createWebDappAdapter(factoryOptions = {}) {
|
|
|
486
524
|
`${cli} launch --adapter ${adapterId} --cdp-port <port> --watcher-port <app port>`,
|
|
487
525
|
);
|
|
488
526
|
}
|
|
489
|
-
const args =
|
|
490
|
-
webDappLeafPath('launch'),
|
|
491
|
-
'--target',
|
|
492
|
-
target,
|
|
493
|
-
'--cdp-port',
|
|
494
|
-
cdpPort,
|
|
495
|
-
'--app-port',
|
|
496
|
-
appPort,
|
|
497
|
-
'--signer',
|
|
498
|
-
str(options, 'signer') ?? process.env.TERMINAL_SIGNER ?? defaultSigner(signerModule),
|
|
499
|
-
'--account',
|
|
500
|
-
str(options, 'account') ?? process.env.TERMINAL_ACCOUNT ?? 'dev1',
|
|
501
|
-
'--json',
|
|
502
|
-
];
|
|
527
|
+
const args = webDappLaunchArgv({ target, cdpPort, appPort, options, signerModule });
|
|
503
528
|
if (signerModule) args.push('--signer-module', signerModule);
|
|
504
529
|
if (flag(options, 'freshProfile')) args.push('--fresh-profile');
|
|
505
530
|
if (flag(options, 'headless')) args.push('--headless');
|
|
@@ -609,7 +634,7 @@ export function createWebDappAdapter(factoryOptions = {}) {
|
|
|
609
634
|
appPort: webDappAppPort(),
|
|
610
635
|
cdpPort: webDappCdpPort(),
|
|
611
636
|
signer: process.env.TERMINAL_SIGNER || defaultSigner(signerModule),
|
|
612
|
-
account: process.env.TERMINAL_ACCOUNT || '
|
|
637
|
+
account: process.env.TERMINAL_ACCOUNT || '',
|
|
613
638
|
probeBrowser: resolveBrowser,
|
|
614
639
|
});
|
|
615
640
|
return report.checks.map((item) => ({
|
package/src/web-dapp/launch.mjs
CHANGED
|
@@ -47,6 +47,7 @@ import path from 'node:path';
|
|
|
47
47
|
import { fileURLToPath } from 'node:url';
|
|
48
48
|
|
|
49
49
|
import { disableMacCodeSignClone } from '../chrome-args.cjs';
|
|
50
|
+
import { isAppUrl } from '../origin.cjs';
|
|
50
51
|
|
|
51
52
|
import { blindBrowserOptions } from './lib/blind-browser.mjs';
|
|
52
53
|
import { hostResolverRules } from './lib/blocked-hosts.mjs';
|
|
@@ -74,6 +75,7 @@ import {
|
|
|
74
75
|
loadWalletFixture,
|
|
75
76
|
resolveSigner,
|
|
76
77
|
walletAccount,
|
|
78
|
+
walletAccounts,
|
|
77
79
|
webDappPolicy,
|
|
78
80
|
webDappRuntimeDir,
|
|
79
81
|
} from './lib/runtime.mjs';
|
|
@@ -93,7 +95,7 @@ function usage() {
|
|
|
93
95
|
|
|
94
96
|
export function parseLaunchArgs(argv, env = process.env) {
|
|
95
97
|
const args = {
|
|
96
|
-
account: '
|
|
98
|
+
account: '',
|
|
97
99
|
'fresh-profile': false,
|
|
98
100
|
headless: false,
|
|
99
101
|
headful: false,
|
|
@@ -284,8 +286,8 @@ function focusLog(runtime, message) {
|
|
|
284
286
|
}
|
|
285
287
|
|
|
286
288
|
// Browser-level CDP helpers for a background launch.
|
|
287
|
-
async function withBrowserClient(cdpPort, callback) {
|
|
288
|
-
const client = await CdpClient.connect(await browserWebSocketUrl(cdpPort,
|
|
289
|
+
async function withBrowserClient(cdpPort, callback, timeoutMs = 15000) {
|
|
290
|
+
const client = await CdpClient.connect(await browserWebSocketUrl(cdpPort, timeoutMs));
|
|
289
291
|
try {
|
|
290
292
|
return await callback(client);
|
|
291
293
|
} finally {
|
|
@@ -293,6 +295,29 @@ async function withBrowserClient(cdpPort, callback) {
|
|
|
293
295
|
}
|
|
294
296
|
}
|
|
295
297
|
|
|
298
|
+
export async function hasHealthyAppPage(client, appOrigin) {
|
|
299
|
+
const { targetInfos } = await client.send('Target.getTargets');
|
|
300
|
+
const page = targetInfos.find(
|
|
301
|
+
(target) => target.type === 'page' && isAppUrl(target.url, appOrigin),
|
|
302
|
+
);
|
|
303
|
+
if (!page) return false;
|
|
304
|
+
const { sessionId } = await client.send('Target.attachToTarget', {
|
|
305
|
+
targetId: page.targetId,
|
|
306
|
+
flatten: true,
|
|
307
|
+
});
|
|
308
|
+
const { result } = await client.send(
|
|
309
|
+
'Runtime.evaluate',
|
|
310
|
+
{
|
|
311
|
+
// Next can keep the requested URL when it replaces the app with its error document.
|
|
312
|
+
expression:
|
|
313
|
+
"!document.documentURI.startsWith('chrome-error:') && document.documentElement?.id !== '__next_error__'",
|
|
314
|
+
returnByValue: true,
|
|
315
|
+
},
|
|
316
|
+
sessionId,
|
|
317
|
+
);
|
|
318
|
+
return result?.value === true;
|
|
319
|
+
}
|
|
320
|
+
|
|
296
321
|
export function backgroundWindowParams(url, placement) {
|
|
297
322
|
return {
|
|
298
323
|
url,
|
|
@@ -514,7 +539,18 @@ export async function launchWebDappBrowser(
|
|
|
514
539
|
|
|
515
540
|
const { fixture } = await loadWalletFixture(target, env);
|
|
516
541
|
// --account is an account name or address; the browser runs under its name.
|
|
517
|
-
|
|
542
|
+
// Without one, keep the browser's current account (else the fixture's first).
|
|
543
|
+
// Only a live browser's record names the current account; a stale record does not.
|
|
544
|
+
const recorded = readStateFile(stateFile);
|
|
545
|
+
const browserLive = Boolean(recorded) && ownsProcess('browser', recorded.browserPid, runtime);
|
|
546
|
+
const current = !args.account && browserLive ? recorded.account : undefined;
|
|
547
|
+
// The current account by its recorded name when that name still holds its address (aliases share one).
|
|
548
|
+
const sameAccount = (candidate) =>
|
|
549
|
+
candidate.name === current?.name &&
|
|
550
|
+
candidate.address.toLowerCase() === String(current?.address ?? '').toLowerCase();
|
|
551
|
+
const selected =
|
|
552
|
+
(current && walletAccounts(fixture, target, env).find(sameAccount)) ??
|
|
553
|
+
walletAccount(fixture, args.account || current?.address, target, env);
|
|
518
554
|
const account = {
|
|
519
555
|
name: selected.name,
|
|
520
556
|
address: selected.address,
|
|
@@ -522,9 +558,9 @@ export async function launchWebDappBrowser(
|
|
|
522
558
|
index: selected.index,
|
|
523
559
|
};
|
|
524
560
|
|
|
525
|
-
const previous =
|
|
561
|
+
const previous = recorded;
|
|
526
562
|
const reusable =
|
|
527
|
-
|
|
563
|
+
browserLive &&
|
|
528
564
|
!args['fresh-profile'] &&
|
|
529
565
|
previous.signer === signer &&
|
|
530
566
|
previous.cdpPort === cdpPort &&
|
|
@@ -535,16 +571,19 @@ export async function launchWebDappBrowser(
|
|
|
535
571
|
Boolean(previous.browser?.outerSeatbelt) === blindBrowser.direct &&
|
|
536
572
|
(previous.network ?? 'testnet') === network &&
|
|
537
573
|
previous.networkEnforcement?.fingerprint === enforcementFingerprint &&
|
|
538
|
-
ownsProcess('browser', previous.browserPid, runtime) &&
|
|
539
574
|
ownsProcess('wallet-host', previous.hostPid, runtime);
|
|
540
|
-
if (
|
|
541
|
-
|
|
575
|
+
if (
|
|
576
|
+
reusable &&
|
|
577
|
+
(await withBrowserClient(cdpPort, (client) => hasHealthyAppPage(client, appOrigin), 5000))
|
|
578
|
+
) {
|
|
542
579
|
log(`reusing browser pid ${previous.browserPid} (${signer}, ${account.name})`);
|
|
543
580
|
const state = { ...previous, slowMoMs };
|
|
544
581
|
if (previous.slowMoMs !== slowMoMs)
|
|
545
582
|
writePrivateFile(stateFile, `${JSON.stringify(state, null, 2)}\n`);
|
|
546
583
|
return { ...state, reused: true };
|
|
547
584
|
}
|
|
585
|
+
if (reusable)
|
|
586
|
+
log('restarting the slot browser because its app tab is missing or on an error page');
|
|
548
587
|
await stopWebDappBrowser(target, { cdpPort, log });
|
|
549
588
|
|
|
550
589
|
const browser = await resolveBrowser(env);
|
|
@@ -604,7 +643,7 @@ export async function launchWebDappBrowser(
|
|
|
604
643
|
target,
|
|
605
644
|
runtime,
|
|
606
645
|
profile,
|
|
607
|
-
account: account.
|
|
646
|
+
account: account.address,
|
|
608
647
|
fixture,
|
|
609
648
|
env,
|
|
610
649
|
freshProfile,
|
|
@@ -716,7 +755,7 @@ export async function launchWebDappBrowser(
|
|
|
716
755
|
'--target',
|
|
717
756
|
target,
|
|
718
757
|
'--account',
|
|
719
|
-
account.
|
|
758
|
+
account.address,
|
|
720
759
|
'--start-chain',
|
|
721
760
|
String(args['start-chain'] ?? policy.startChain),
|
|
722
761
|
'--network',
|
|
@@ -247,7 +247,7 @@ export async function webDappReadiness({
|
|
|
247
247
|
cdpPort,
|
|
248
248
|
// As defaultSigner: extension only when the host gave an extension signer.
|
|
249
249
|
signer = signers?.extension ? 'extension' : 'injected',
|
|
250
|
-
account = '
|
|
250
|
+
account = '',
|
|
251
251
|
env = process.env,
|
|
252
252
|
probeBrowser = undefined,
|
|
253
253
|
}) {
|
|
@@ -304,7 +304,11 @@ export async function webDappReadiness({
|
|
|
304
304
|
const { file, fixture } = await loadWalletFixture(target, env);
|
|
305
305
|
const { address } = walletAccount(fixture, account, target, env);
|
|
306
306
|
checks.push(
|
|
307
|
-
check(
|
|
307
|
+
check(
|
|
308
|
+
'wallet-fixture',
|
|
309
|
+
true,
|
|
310
|
+
`${path.basename(file)}: account ${account || '(first)'} -> ${address}`,
|
|
311
|
+
),
|
|
308
312
|
);
|
|
309
313
|
} catch (error) {
|
|
310
314
|
checks.push(check('wallet-fixture', false, error.message.split('\n')[0]));
|
|
@@ -14,7 +14,9 @@ import { loadViemAccounts } from './viem.mjs';
|
|
|
14
14
|
export { POLICY_ENV, webDappAdapterId, webDappPolicy };
|
|
15
15
|
|
|
16
16
|
export const SIGNER_MODES = Object.freeze(['extension', 'injected']);
|
|
17
|
-
|
|
17
|
+
// No account named: the browser's current account, else the fixture's first one.
|
|
18
|
+
// Fixture account names differ between people, so none is assumed.
|
|
19
|
+
export const DEFAULT_ACCOUNT = '';
|
|
18
20
|
|
|
19
21
|
// The checkout's canonical path: a symlinked or /tmp-vs-/private/tmp spelling
|
|
20
22
|
// of the same slot must name the same runtime dir, profile and pid owners.
|
|
@@ -246,8 +248,9 @@ export function walletAccounts(fixture, projectRoot, env = process.env) {
|
|
|
246
248
|
const count = entry.type === 'mnemonic' ? mnemonicCount(entry) : 1;
|
|
247
249
|
for (let index = 0; index < count; index += 1) {
|
|
248
250
|
const account = viemAccountFromEntry(entry, projectRoot, index);
|
|
251
|
+
const name = derivedName(entry, index, count);
|
|
249
252
|
accounts.push({
|
|
250
|
-
name
|
|
253
|
+
name,
|
|
251
254
|
address: account.address,
|
|
252
255
|
secret: entry.name,
|
|
253
256
|
index,
|
|
@@ -296,11 +299,11 @@ export function walletAccounts(fixture, projectRoot, env = process.env) {
|
|
|
296
299
|
export function walletAccount(fixture, selector, projectRoot, env = process.env) {
|
|
297
300
|
const accounts = walletAccounts(fixture, projectRoot, env);
|
|
298
301
|
const wanted = String(selector ?? '').trim();
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
302
|
+
if (!wanted && accounts.length > 0) return accounts[0];
|
|
303
|
+
// An address selects by address, never by an entry that happens to be named like it.
|
|
304
|
+
const found = /^0x[0-9a-fA-F]{40}$/u.test(wanted)
|
|
305
|
+
? accounts.find((account) => account.address.toLowerCase() === wanted.toLowerCase())
|
|
306
|
+
: accounts.find((account) => account.name === wanted);
|
|
304
307
|
if (!found) {
|
|
305
308
|
const names = accounts.map((account) => account.name).join(', ');
|
|
306
309
|
throw new Error(`wallet fixture has no account named "${wanted}". Available: ${names}.`);
|
|
@@ -321,8 +324,20 @@ export async function resolveAccountAddress(input, env = process.env) {
|
|
|
321
324
|
return { name: null, address: raw.trim() };
|
|
322
325
|
}
|
|
323
326
|
const projectRoot = input.context?.projectRoot;
|
|
324
|
-
const
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
327
|
+
const explicit = String(input.node?.account_name ?? input.node?.account ?? '').trim();
|
|
328
|
+
let browserState = null;
|
|
329
|
+
if (!explicit && projectRoot) {
|
|
330
|
+
const recorded = await readBrowserState(projectRoot);
|
|
331
|
+
// Only a running browser's record names the current account (lazy import: processes.mjs imports this module).
|
|
332
|
+
const { ownsProcess } = await import('./processes.mjs');
|
|
333
|
+
if (recorded && ownsProcess('browser', recorded.browserPid, webDappRuntimeDir(projectRoot))) {
|
|
334
|
+
browserState = recorded;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
if (browserState?.account?.address) {
|
|
338
|
+
return { name: browserState.account.name ?? null, address: browserState.account.address };
|
|
339
|
+
}
|
|
340
|
+
const { fixture } = await loadWalletFixture(projectRoot, env);
|
|
341
|
+
const selected = walletAccount(fixture, accountName(input, browserState), projectRoot, env);
|
|
342
|
+
return { name: selected.name, address: selected.address };
|
|
328
343
|
}
|
package/src/web-dapp/verify.mjs
CHANGED
|
@@ -45,7 +45,7 @@ if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.me
|
|
|
45
45
|
),
|
|
46
46
|
cdpPort: num(value('--cdp-port') ?? process.env.RECIPE_CDP_PORT ?? process.env.CDP_PORT),
|
|
47
47
|
signer: value('--signer') ?? process.env.TERMINAL_SIGNER ?? defaultSigner(signerModule),
|
|
48
|
-
account: value('--account') ?? process.env.TERMINAL_ACCOUNT ?? '
|
|
48
|
+
account: value('--account') ?? process.env.TERMINAL_ACCOUNT ?? '',
|
|
49
49
|
probeBrowser: resolveBrowser,
|
|
50
50
|
});
|
|
51
51
|
if (argv.includes('--json')) {
|