@farmslot/adapter-web 0.19.31 → 0.19.33
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
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.33 - 2026-11-24
|
|
10
|
+
|
|
11
|
+
- A Terminal (web-dapp) launch with no display choice runs headless when the macOS session is locked, instead of refusing with SESSION_LOCKED. Headful stays the default when the screen can paint; an explicit `--headful` or `TERMINAL_HEADLESS=0` on a locked session still refuses.
|
|
12
|
+
|
|
13
|
+
## 0.19.32 - 2026-11-24
|
|
14
|
+
|
|
15
|
+
- The injected wallet presented as MetaMask also answers the extension's window streams (`metamask-provider` and the `metamask-multichain-provider` session API), so apps that log in through `@metamask/connect-multichain`, such as the Web Terminal's Web3Auth login, finish starting and can connect.
|
|
16
|
+
|
|
9
17
|
## 0.19.31 - 2026-11-23
|
|
10
18
|
|
|
11
19
|
- Pin the Recipe Runner 0.52.2 cohort.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export function resolveHeadless({ headless, headful, nodeHeadless, nodeHeadful, env, }?: {
|
|
1
|
+
export function resolveHeadless({ headless, headful, nodeHeadless, nodeHeadful, env, sessionLocked, }?: {
|
|
2
2
|
env?: NodeJS.ProcessEnv | undefined;
|
|
3
|
+
sessionLocked?: (() => boolean) | undefined;
|
|
3
4
|
}): boolean;
|
|
4
5
|
export function resolveSlowMo({ flag, node, env }?: {
|
|
5
6
|
env?: NodeJS.ProcessEnv | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farmslot/adapter-web",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.33",
|
|
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": {
|
package/src/dapp/page-script.cjs
CHANGED
|
@@ -44,6 +44,16 @@ const ERROR_CATEGORIES = Object.freeze({
|
|
|
44
44
|
[-32603]: 'internal',
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
+
// The MetaMask extension's window-message streams, which an injected wallet
|
|
48
|
+
// presented as MetaMask also answers.
|
|
49
|
+
const EXTENSION_STREAMS = Object.freeze({
|
|
50
|
+
contentscript: 'metamask-contentscript',
|
|
51
|
+
inpage: 'metamask-inpage',
|
|
52
|
+
provider: 'metamask-provider',
|
|
53
|
+
multichain: 'metamask-multichain-provider',
|
|
54
|
+
sessionKey: '__farmslotMultichainSession',
|
|
55
|
+
});
|
|
56
|
+
|
|
47
57
|
function pageMain(config, refusalReason) {
|
|
48
58
|
if (window.top !== window || location.origin !== config.appOrigin) return;
|
|
49
59
|
if (window[config.marker]) return;
|
|
@@ -249,9 +259,127 @@ function pageMain(config, refusalReason) {
|
|
|
249
259
|
);
|
|
250
260
|
window.addEventListener('eip6963:requestProvider', announce);
|
|
251
261
|
announce();
|
|
262
|
+
if (config.injectedWallet.isMetaMask) serveExtensionStreams(provider);
|
|
252
263
|
return;
|
|
253
264
|
}
|
|
254
265
|
|
|
266
|
+
// A wallet presented as MetaMask is taken for the extension, so apps also
|
|
267
|
+
// reach it over the extension's window streams (as @metamask/connect-multichain
|
|
268
|
+
// does): `metamask-provider` (EIP-1193 JSON-RPC) and `metamask-multichain-provider`
|
|
269
|
+
// (CAIP-25 sessions). Both are answered from the same provider, so every
|
|
270
|
+
// request still goes to the host and is logged. The session's scopes persist
|
|
271
|
+
// per profile, as the extension's permissions do.
|
|
272
|
+
function serveExtensionStreams(provider) {
|
|
273
|
+
const streams = config.extensionStreams;
|
|
274
|
+
const reply = (name, data) =>
|
|
275
|
+
window.postMessage({ target: streams.inpage, data: { name, data } }, location.origin);
|
|
276
|
+
const chainOf = (scope) => Number.parseInt(String(scope).split(':')[1], 10);
|
|
277
|
+
let saved = [];
|
|
278
|
+
const readScopes = () => {
|
|
279
|
+
try {
|
|
280
|
+
const stored = JSON.parse(window.localStorage.getItem(streams.sessionKey) ?? '[]');
|
|
281
|
+
return Array.isArray(stored) ? stored : [];
|
|
282
|
+
} catch {
|
|
283
|
+
// Corrupt or blocked storage reads as no session.
|
|
284
|
+
return [];
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
const writeScopes = (scopes) => {
|
|
288
|
+
try {
|
|
289
|
+
if (scopes.length) window.localStorage.setItem(streams.sessionKey, JSON.stringify(scopes));
|
|
290
|
+
else window.localStorage.removeItem(streams.sessionKey);
|
|
291
|
+
} catch {
|
|
292
|
+
// No storage (opaque origin): the session lasts for this document.
|
|
293
|
+
}
|
|
294
|
+
saved = scopes;
|
|
295
|
+
};
|
|
296
|
+
saved = readScopes();
|
|
297
|
+
const session = async () => {
|
|
298
|
+
if (!saved.length) return { sessionScopes: {} };
|
|
299
|
+
const accounts = await provider.request({ method: 'eth_accounts' });
|
|
300
|
+
const sessionScopes = {};
|
|
301
|
+
for (const scope of saved) {
|
|
302
|
+
sessionScopes[scope] = {
|
|
303
|
+
accounts: accounts.map((address) => `${scope}:${address}`),
|
|
304
|
+
// The wallet methods the host signs and logs.
|
|
305
|
+
methods: config.loggedMethods,
|
|
306
|
+
notifications: [],
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
return { sessionScopes };
|
|
310
|
+
};
|
|
311
|
+
const changed = async () =>
|
|
312
|
+
reply(streams.multichain, { method: 'wallet_sessionChanged', params: await session() });
|
|
313
|
+
const multichain = {
|
|
314
|
+
wallet_getSession: session,
|
|
315
|
+
async wallet_createSession(params) {
|
|
316
|
+
const requested = Object.keys({ ...params?.requiredScopes, ...params?.optionalScopes });
|
|
317
|
+
const scopes = requested.filter((scope) => /^eip155:\d+$/u.test(scope));
|
|
318
|
+
if (!scopes.length) {
|
|
319
|
+
scopes.push(
|
|
320
|
+
`eip155:${Number.parseInt(await provider.request({ method: 'eth_chainId' }), 16)}`,
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
await provider.request({ method: 'eth_requestAccounts' });
|
|
324
|
+
writeScopes(scopes);
|
|
325
|
+
const result = await session();
|
|
326
|
+
await changed();
|
|
327
|
+
return result;
|
|
328
|
+
},
|
|
329
|
+
async wallet_revokeSession() {
|
|
330
|
+
writeScopes([]);
|
|
331
|
+
await changed();
|
|
332
|
+
return true;
|
|
333
|
+
},
|
|
334
|
+
async wallet_invokeMethod(params) {
|
|
335
|
+
const chain = chainOf(params?.scope);
|
|
336
|
+
if (!saved.includes(params?.scope)) {
|
|
337
|
+
throw Object.assign(new Error(`${params?.scope} is not in the session.`), { code: 4100 });
|
|
338
|
+
}
|
|
339
|
+
if (Number.parseInt(await provider.request({ method: 'eth_chainId' }), 16) !== chain) {
|
|
340
|
+
await provider.request({
|
|
341
|
+
method: 'wallet_switchEthereumChain',
|
|
342
|
+
params: [{ chainId: `0x${chain.toString(16)}` }],
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
return provider.request(params.request);
|
|
346
|
+
},
|
|
347
|
+
};
|
|
348
|
+
const answer = async (name, message, handle) => {
|
|
349
|
+
try {
|
|
350
|
+
reply(name, { jsonrpc: '2.0', id: message.id, result: await handle() });
|
|
351
|
+
} catch (error) {
|
|
352
|
+
reply(name, {
|
|
353
|
+
jsonrpc: '2.0',
|
|
354
|
+
id: message.id,
|
|
355
|
+
error: {
|
|
356
|
+
code: Number.isInteger(error?.code) ? error.code : -32603,
|
|
357
|
+
message: String(error?.message ?? error),
|
|
358
|
+
},
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
window.addEventListener('message', (event) => {
|
|
363
|
+
if (event.source !== window || event.origin !== location.origin) return;
|
|
364
|
+
if (event.data?.target !== streams.contentscript) return;
|
|
365
|
+
const name = event.data.data?.name;
|
|
366
|
+
const message = event.data.data?.data;
|
|
367
|
+
if (!message || message.id === undefined || typeof message.method !== 'string') return;
|
|
368
|
+
if (name === streams.provider) {
|
|
369
|
+
answer(name, message, () =>
|
|
370
|
+
provider.request({ method: message.method, params: message.params }),
|
|
371
|
+
);
|
|
372
|
+
} else if (name === streams.multichain) {
|
|
373
|
+
const handle = multichain[message.method];
|
|
374
|
+
answer(name, message, () => {
|
|
375
|
+
if (!handle)
|
|
376
|
+
throw Object.assign(new Error(`${message.method} is not supported`), { code: 4200 });
|
|
377
|
+
return handle(message.params);
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
|
|
255
383
|
// Extension mode: wrap whatever provider the wallet extension injects,
|
|
256
384
|
// however the app reaches it (window.ethereum or an EIP-6963 announcement).
|
|
257
385
|
let current = window.ethereum ? wrap(window.ethereum, 'window.ethereum') : undefined;
|
|
@@ -359,6 +487,7 @@ function pageScriptSource({ signer, appOrigin, refuseTypedData = null, injectedW
|
|
|
359
487
|
? { info: injectedWallet.info, isMetaMask: injectedWallet.isMetaMask === true }
|
|
360
488
|
: null,
|
|
361
489
|
errorCategories: ERROR_CATEGORIES,
|
|
490
|
+
extensionStreams: EXTENSION_STREAMS,
|
|
362
491
|
loggedMethods: LOGGED_METHODS,
|
|
363
492
|
marker: PAGE_MARKER,
|
|
364
493
|
logBinding: LOG_BINDING,
|
package/src/web-dapp/launch.mjs
CHANGED
|
@@ -485,11 +485,28 @@ export async function launchWebDappBrowser(
|
|
|
485
485
|
chmodSync(runtime, 0o700);
|
|
486
486
|
const stateFile = path.join(runtime, 'browser.json');
|
|
487
487
|
const appOrigin = `http://localhost:${appPort}`;
|
|
488
|
-
|
|
488
|
+
// The session is probed at most once: by the default display choice, or by
|
|
489
|
+
// the refusal below.
|
|
490
|
+
let probed = false;
|
|
491
|
+
let locked;
|
|
492
|
+
const probeLock = () => {
|
|
493
|
+
if (!probed) {
|
|
494
|
+
probed = true;
|
|
495
|
+
locked = sessionLocked();
|
|
496
|
+
}
|
|
497
|
+
return locked;
|
|
498
|
+
};
|
|
499
|
+
const headless = resolveHeadless({
|
|
500
|
+
headless: args.headless,
|
|
501
|
+
headful: args.headful,
|
|
502
|
+
env,
|
|
503
|
+
sessionLocked: () => probeLock() === true,
|
|
504
|
+
});
|
|
489
505
|
const slowMoMs = resolveSlowMo({ flag: args['slow-mo'], env });
|
|
490
|
-
|
|
491
|
-
//
|
|
492
|
-
|
|
506
|
+
if (headless && locked === true) log('the macOS session is locked: launching headless');
|
|
507
|
+
// A headful browser that was asked for can't paint while the macOS session
|
|
508
|
+
// is locked: refuse before starting, reusing or stopping one.
|
|
509
|
+
if (!headless && probeLock() === true) {
|
|
493
510
|
throw new Error(
|
|
494
511
|
`SESSION_LOCKED: ${SESSION_LOCKED_MESSAGE}\nNext: ${SESSION_LOCKED_USER_ACTION}`,
|
|
495
512
|
);
|
|
@@ -19,13 +19,15 @@ function envFlag(raw, label) {
|
|
|
19
19
|
|
|
20
20
|
// Headless precedence: an explicit flag (--headless, or --headful as its
|
|
21
21
|
// opposite) → the launch node (headless, or headful as its opposite) → env
|
|
22
|
-
// TERMINAL_HEADLESS → headful
|
|
22
|
+
// TERMINAL_HEADLESS → headful, or headless when `sessionLocked` says the macOS
|
|
23
|
+
// session is locked (a headful browser can't paint there).
|
|
23
24
|
export function resolveHeadless({
|
|
24
25
|
headless,
|
|
25
26
|
headful,
|
|
26
27
|
nodeHeadless,
|
|
27
28
|
nodeHeadful,
|
|
28
29
|
env = process.env,
|
|
30
|
+
sessionLocked = () => false,
|
|
29
31
|
} = {}) {
|
|
30
32
|
if (headless === true && headful === true)
|
|
31
33
|
throw new Error('--headless and --headful are mutually exclusive.');
|
|
@@ -33,7 +35,12 @@ export function resolveHeadless({
|
|
|
33
35
|
if (headful === true) return false;
|
|
34
36
|
if (typeof nodeHeadless === 'boolean') return nodeHeadless;
|
|
35
37
|
if (nodeHeadful === true) return false;
|
|
36
|
-
|
|
38
|
+
// An empty TERMINAL_HEADLESS chooses nothing, like an unset one.
|
|
39
|
+
const raw = env.TERMINAL_HEADLESS;
|
|
40
|
+
const fromEnv =
|
|
41
|
+
raw == null || String(raw).trim() === '' ? undefined : envFlag(raw, 'TERMINAL_HEADLESS');
|
|
42
|
+
if (fromEnv !== undefined) return fromEnv;
|
|
43
|
+
return sessionLocked() === true;
|
|
37
44
|
}
|
|
38
45
|
|
|
39
46
|
function slowMoValue(raw, label) {
|