@gruu6y/page-clean-login 0.2.10 → 0.2.12
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/account-browser.mjs +459 -0
- package/lib/agent-cli.mjs +22 -0
- package/lib/agent-surface.mjs +15 -3
- package/lib/browser-launcher.mjs +142 -36
- package/lib/renew-hosting.mjs +33 -0
- package/lib/server.mjs +166 -14
- package/lib/signin-flow.mjs +12 -0
- package/package.json +2 -2
- package/ui/account-view.js +140 -1
- package/ui/app.js +403 -0
- package/ui/index.html +5 -0
- package/ui/style.css +33 -0
package/lib/browser-launcher.mjs
CHANGED
|
@@ -196,18 +196,67 @@ async function defaultCheckExecutable(executablePath) {
|
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
-
|
|
199
|
+
const ACCOUNT_PURPOSE = "account";
|
|
200
|
+
const BLANK_URL = "about:blank";
|
|
201
|
+
|
|
202
|
+
function normalizePurpose(purpose) {
|
|
203
|
+
return purpose === ACCOUNT_PURPOSE ? ACCOUNT_PURPOSE : "signin";
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function normalizeLaunchUrl(url, purpose) {
|
|
207
|
+
if (purpose !== ACCOUNT_PURPOSE) {
|
|
208
|
+
if (typeof url !== "string" || !url) {
|
|
209
|
+
throw new SignInBrowserError("url_missing", "The sign-in method returned no URL.", 502);
|
|
210
|
+
}
|
|
211
|
+
return url;
|
|
212
|
+
}
|
|
213
|
+
if (url === undefined || url === null) return BLANK_URL;
|
|
214
|
+
if (typeof url !== "string") {
|
|
215
|
+
throw new SignInBrowserError("invalid_url", "The account browser URL must be a string.", 400);
|
|
216
|
+
}
|
|
217
|
+
const trimmed = url.trim();
|
|
218
|
+
if (!trimmed || trimmed.toLowerCase() === BLANK_URL) return BLANK_URL;
|
|
219
|
+
if (/[\u0000-\u001f\u007f]/.test(trimmed)) {
|
|
220
|
+
throw new SignInBrowserError("invalid_url", "The account browser URL is invalid.", 400);
|
|
221
|
+
}
|
|
222
|
+
let parsed;
|
|
223
|
+
try {
|
|
224
|
+
parsed = new URL(trimmed);
|
|
225
|
+
} catch {
|
|
226
|
+
throw new SignInBrowserError("invalid_url", "The account browser URL is invalid.", 400);
|
|
227
|
+
}
|
|
228
|
+
if ((parsed.protocol !== "http:" && parsed.protocol !== "https:") || !parsed.hostname) {
|
|
229
|
+
throw new SignInBrowserError(
|
|
230
|
+
"invalid_url",
|
|
231
|
+
"The account browser only opens http:, https:, or about:blank URLs.",
|
|
232
|
+
400,
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
if (parsed.username || parsed.password) {
|
|
236
|
+
throw new SignInBrowserError(
|
|
237
|
+
"invalid_url",
|
|
238
|
+
"The account browser URL must not contain embedded credentials.",
|
|
239
|
+
400,
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
return parsed.href;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
async function assertExecutable(executablePath, check, { isAccount = false } = {}) {
|
|
246
|
+
const browserLabel = isAccount ? "account browser" : "login browser";
|
|
200
247
|
if (typeof executablePath !== "string" || !executablePath) {
|
|
201
248
|
throw new SignInBrowserError(
|
|
202
249
|
"executable_missing",
|
|
203
|
-
|
|
250
|
+
`The ${browserLabel} is not installed; prepare it on the Providers page first.`,
|
|
204
251
|
503,
|
|
205
252
|
);
|
|
206
253
|
}
|
|
207
254
|
if (!(await check(executablePath))) {
|
|
208
255
|
throw new SignInBrowserError(
|
|
209
256
|
"executable_missing",
|
|
210
|
-
|
|
257
|
+
isAccount
|
|
258
|
+
? "The account browser executable was not found; prepare it on the Providers page first."
|
|
259
|
+
: `The ${browserLabel} executable was not found at ${executablePath}.`,
|
|
211
260
|
503,
|
|
212
261
|
);
|
|
213
262
|
}
|
|
@@ -224,19 +273,21 @@ export async function openSignInBrowser({
|
|
|
224
273
|
modelDir,
|
|
225
274
|
headless = false,
|
|
226
275
|
navTimeoutMs = DEFAULT_NAVIGATION_TIMEOUT_MS,
|
|
276
|
+
purpose = "signin",
|
|
227
277
|
deps = {},
|
|
228
278
|
} = {}) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
279
|
+
const normalizedPurpose = normalizePurpose(purpose);
|
|
280
|
+
const isAccount = normalizedPurpose === ACCOUNT_PURPOSE;
|
|
281
|
+
const browserLabel = isAccount ? "account browser" : "login browser";
|
|
282
|
+
const targetUrl = normalizeLaunchUrl(url, normalizedPurpose);
|
|
232
283
|
if (!profileDir) {
|
|
233
284
|
throw new SignInBrowserError("profile_missing", "The account has no browser profile directory.", 500);
|
|
234
285
|
}
|
|
235
286
|
const navigationTimeoutMs = normalizeNavTimeoutMs(navTimeoutMs);
|
|
236
|
-
await assertExecutable(executablePath, deps.checkExecutable ?? defaultCheckExecutable);
|
|
287
|
+
await assertExecutable(executablePath, deps.checkExecutable ?? defaultCheckExecutable, { isAccount });
|
|
237
288
|
await mkdir(profileDir, { recursive: true, mode: 0o700 });
|
|
238
289
|
|
|
239
|
-
const input = buildLaunchInput({ url, profileDir, identity, proxy, modelDir, headless });
|
|
290
|
+
const input = buildLaunchInput({ url: targetUrl, profileDir, identity, proxy, modelDir, headless });
|
|
240
291
|
// fpgen resolves its model directory as `configuredDir || FPGEN_DATA_DIR ||
|
|
241
292
|
// userCacheDir("fpgen")`, with one module-level `configuredDir`. Setting the
|
|
242
293
|
// correctly named FPGEN_DATA_DIR here is only a fallback: importing camoufox
|
|
@@ -250,7 +301,9 @@ export async function openSignInBrowser({
|
|
|
250
301
|
} catch (error) {
|
|
251
302
|
throw new SignInBrowserError(
|
|
252
303
|
"runtime_missing",
|
|
253
|
-
|
|
304
|
+
isAccount
|
|
305
|
+
? "The account browser runtime could not be loaded."
|
|
306
|
+
: `The ${browserLabel} runtime could not be loaded: ${String(error?.message ?? error)}`,
|
|
254
307
|
503,
|
|
255
308
|
);
|
|
256
309
|
}
|
|
@@ -266,7 +319,9 @@ export async function openSignInBrowser({
|
|
|
266
319
|
} catch (error) {
|
|
267
320
|
throw new SignInBrowserError(
|
|
268
321
|
"runtime_missing",
|
|
269
|
-
|
|
322
|
+
isAccount
|
|
323
|
+
? "The fingerprint runtime could not be loaded."
|
|
324
|
+
: `The fingerprint runtime could not be loaded: ${String(error?.message ?? error)}`,
|
|
270
325
|
503,
|
|
271
326
|
);
|
|
272
327
|
}
|
|
@@ -277,11 +332,14 @@ export async function openSignInBrowser({
|
|
|
277
332
|
} catch (error) {
|
|
278
333
|
throw new SignInBrowserError(
|
|
279
334
|
"runtime_missing",
|
|
280
|
-
|
|
335
|
+
isAccount
|
|
336
|
+
? "The browser automation runtime could not be loaded."
|
|
337
|
+
: `playwright-core could not be loaded: ${String(error?.message ?? error)}`,
|
|
281
338
|
503,
|
|
282
339
|
);
|
|
283
340
|
}
|
|
284
341
|
|
|
342
|
+
const shouldNavigate = !isAccount || targetUrl !== BLANK_URL;
|
|
285
343
|
let context;
|
|
286
344
|
let page;
|
|
287
345
|
try {
|
|
@@ -301,8 +359,8 @@ export async function openSignInBrowser({
|
|
|
301
359
|
headless: Boolean(headless),
|
|
302
360
|
});
|
|
303
361
|
page = context.pages?.()[0] ?? (await context.newPage());
|
|
304
|
-
if (!page || typeof page.goto !== "function") {
|
|
305
|
-
throw new Error(
|
|
362
|
+
if (!page || (shouldNavigate && typeof page.goto !== "function")) {
|
|
363
|
+
throw new Error(`The ${browserLabel} opened no page.`);
|
|
306
364
|
}
|
|
307
365
|
} catch (error) {
|
|
308
366
|
try {
|
|
@@ -312,26 +370,34 @@ export async function openSignInBrowser({
|
|
|
312
370
|
}
|
|
313
371
|
throw new SignInBrowserError(
|
|
314
372
|
"launch_failed",
|
|
315
|
-
|
|
373
|
+
isAccount
|
|
374
|
+
? "The account browser could not be opened."
|
|
375
|
+
: `The ${browserLabel} could not be opened: ${String(error?.message ?? error)}`,
|
|
316
376
|
502,
|
|
317
377
|
);
|
|
318
378
|
}
|
|
319
379
|
|
|
320
380
|
// Navigation is a separate phase: once the browser and page exist, a slow
|
|
321
381
|
// page must not be reported as a failed launch or close the user's window.
|
|
382
|
+
// For account browsers opening on `about:blank`, skip navigation altogether
|
|
383
|
+
// to avoid unnecessary network traffic or timeouts.
|
|
322
384
|
let navigationError = null;
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
385
|
+
if (shouldNavigate) {
|
|
386
|
+
try {
|
|
387
|
+
await page.goto(targetUrl, { waitUntil: NAVIGATION_WAIT_UNTIL, timeout: navigationTimeoutMs });
|
|
388
|
+
} catch (error) {
|
|
389
|
+
const seconds = Math.ceil(navigationTimeoutMs / 1000);
|
|
390
|
+
navigationError = new SignInBrowserError(
|
|
391
|
+
NAVIGATION_ERROR_CODE,
|
|
392
|
+
isAccount
|
|
393
|
+
? `The account browser is open, but the page did not finish loading within ${seconds} seconds. You can continue using the open window.`
|
|
394
|
+
: `The login browser is open, but the page did not finish loading within ${seconds} seconds. You can still complete the sign-in in the open window.`,
|
|
395
|
+
NAVIGATION_STATUS,
|
|
396
|
+
);
|
|
397
|
+
navigationError.timeoutMs = navigationTimeoutMs;
|
|
398
|
+
navigationError.waitUntil = NAVIGATION_WAIT_UNTIL;
|
|
399
|
+
navigationError.detail = String(error?.message ?? error);
|
|
400
|
+
}
|
|
335
401
|
}
|
|
336
402
|
|
|
337
403
|
let closed = false;
|
|
@@ -366,17 +432,19 @@ export async function launchSignInBrowser({
|
|
|
366
432
|
// A hosted renewal has no user watching it: the same profile, the same
|
|
367
433
|
// pinned fingerprint and the same exit, but no window on the desktop.
|
|
368
434
|
headless = false,
|
|
435
|
+
purpose = "signin",
|
|
369
436
|
env = process.env,
|
|
370
437
|
platform = process.platform,
|
|
371
438
|
deps = {},
|
|
372
439
|
} = {}) {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
440
|
+
const normalizedPurpose = normalizePurpose(purpose);
|
|
441
|
+
const isAccount = normalizedPurpose === ACCOUNT_PURPOSE;
|
|
442
|
+
const browserLabel = isAccount ? "account browser" : "login browser";
|
|
443
|
+
const targetUrl = normalizeLaunchUrl(url, normalizedPurpose);
|
|
376
444
|
if (!profileDir) {
|
|
377
445
|
throw new SignInBrowserError("profile_missing", "The account has no browser profile directory.", 500);
|
|
378
446
|
}
|
|
379
|
-
await assertExecutable(executablePath, deps.checkExecutable ?? defaultCheckExecutable);
|
|
447
|
+
await assertExecutable(executablePath, deps.checkExecutable ?? defaultCheckExecutable, { isAccount });
|
|
380
448
|
await mkdir(profileDir, { recursive: true, mode: 0o700 });
|
|
381
449
|
|
|
382
450
|
const resolvedModelDir = modelDir ?? fingerprintModelDir(env);
|
|
@@ -386,13 +454,14 @@ export async function launchSignInBrowser({
|
|
|
386
454
|
// inside the profile directory and has to be cleaned up on every path.
|
|
387
455
|
const payload = JSON.stringify({
|
|
388
456
|
executablePath,
|
|
389
|
-
url,
|
|
457
|
+
url: targetUrl,
|
|
390
458
|
profileDir,
|
|
391
459
|
identity,
|
|
392
460
|
proxy,
|
|
393
461
|
modelDir: resolvedModelDir,
|
|
394
462
|
navTimeoutMs: navigationTimeoutMs,
|
|
395
463
|
headless: Boolean(headless),
|
|
464
|
+
purpose: normalizedPurpose,
|
|
396
465
|
});
|
|
397
466
|
|
|
398
467
|
const spawnHost = deps.fork ?? fork;
|
|
@@ -412,7 +481,9 @@ export async function launchSignInBrowser({
|
|
|
412
481
|
} catch (error) {
|
|
413
482
|
throw new SignInBrowserError(
|
|
414
483
|
"launch_failed",
|
|
415
|
-
|
|
484
|
+
isAccount
|
|
485
|
+
? "The account browser host could not be started."
|
|
486
|
+
: `The ${browserLabel} host could not be started: ${String(error?.message ?? error)}`,
|
|
416
487
|
502,
|
|
417
488
|
);
|
|
418
489
|
}
|
|
@@ -432,7 +503,7 @@ export async function launchSignInBrowser({
|
|
|
432
503
|
fn(value);
|
|
433
504
|
};
|
|
434
505
|
const timer = setTimeout(
|
|
435
|
-
() => done(reject, new SignInBrowserError("launch_timeout",
|
|
506
|
+
() => done(reject, new SignInBrowserError("launch_timeout", `The ${browserLabel} did not open in time.`, 504)),
|
|
436
507
|
timeoutMs,
|
|
437
508
|
);
|
|
438
509
|
child.on("message", (message) => {
|
|
@@ -440,15 +511,50 @@ export async function launchSignInBrowser({
|
|
|
440
511
|
warning = message.warning ?? null;
|
|
441
512
|
done(resolve);
|
|
442
513
|
} else if (message?.type === "error") {
|
|
443
|
-
|
|
514
|
+
const code = typeof message.code === "string" && message.code ? message.code : "launch_failed";
|
|
515
|
+
let safeMessage = String(message.message ?? `The ${browserLabel} failed to open.`);
|
|
516
|
+
if (isAccount) {
|
|
517
|
+
if (code === "executable_missing") {
|
|
518
|
+
safeMessage =
|
|
519
|
+
"The account browser executable was not found; prepare it on the Providers page first.";
|
|
520
|
+
} else if (code === "runtime_missing") {
|
|
521
|
+
safeMessage = "The account browser runtime could not be loaded.";
|
|
522
|
+
} else if (code === "invalid_url") {
|
|
523
|
+
safeMessage = "The account browser only opens http:, https:, or about:blank URLs.";
|
|
524
|
+
} else if (code === "launch_timeout") {
|
|
525
|
+
safeMessage = "The account browser did not open in time.";
|
|
526
|
+
} else {
|
|
527
|
+
safeMessage = "The account browser could not be opened.";
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
done(
|
|
531
|
+
reject,
|
|
532
|
+
new SignInBrowserError(code, safeMessage, message.status ?? 502),
|
|
533
|
+
);
|
|
444
534
|
}
|
|
445
535
|
});
|
|
446
536
|
child.once("error", (error) =>
|
|
447
|
-
done(
|
|
537
|
+
done(
|
|
538
|
+
reject,
|
|
539
|
+
new SignInBrowserError(
|
|
540
|
+
"launch_failed",
|
|
541
|
+
isAccount
|
|
542
|
+
? "The account browser host failed."
|
|
543
|
+
: `The ${browserLabel} host failed: ${String(error?.message ?? error)}`,
|
|
544
|
+
502,
|
|
545
|
+
),
|
|
546
|
+
),
|
|
448
547
|
);
|
|
449
548
|
child.once("exit", (code) => {
|
|
450
549
|
if (!settled) {
|
|
451
|
-
done(
|
|
550
|
+
done(
|
|
551
|
+
reject,
|
|
552
|
+
new SignInBrowserError(
|
|
553
|
+
"launch_failed",
|
|
554
|
+
`The ${browserLabel} host exited before it opened the browser (code ${code}).`,
|
|
555
|
+
502,
|
|
556
|
+
),
|
|
557
|
+
);
|
|
452
558
|
}
|
|
453
559
|
});
|
|
454
560
|
});
|
package/lib/renew-hosting.mjs
CHANGED
|
@@ -215,6 +215,8 @@ export function createRenewHosting(options = {}) {
|
|
|
215
215
|
signIn = null,
|
|
216
216
|
store = null,
|
|
217
217
|
identityCheck = null,
|
|
218
|
+
accountBrowser = null,
|
|
219
|
+
isAccountBrowserOpen = null,
|
|
218
220
|
now = () => Date.now(),
|
|
219
221
|
tickMs = HOSTING_TICK_MS,
|
|
220
222
|
leadMs = HOSTING_LEAD_MS,
|
|
@@ -465,6 +467,18 @@ export function createRenewHosting(options = {}) {
|
|
|
465
467
|
return Boolean(identityCheck.status()?.browserOpen);
|
|
466
468
|
}
|
|
467
469
|
|
|
470
|
+
// An account's standalone fingerprint browser holds the same `profile/` dir,
|
|
471
|
+
// so hosted renewal must never launch on top of it.
|
|
472
|
+
function accountBrowserOpen(provider, key) {
|
|
473
|
+
if (typeof isAccountBrowserOpen === "function") {
|
|
474
|
+
return Boolean(isAccountBrowserOpen(provider, key));
|
|
475
|
+
}
|
|
476
|
+
if (accountBrowser && typeof accountBrowser.isOpen === "function") {
|
|
477
|
+
return Boolean(accountBrowser.isOpen(provider, key));
|
|
478
|
+
}
|
|
479
|
+
return false;
|
|
480
|
+
}
|
|
481
|
+
|
|
468
482
|
async function record(entry, attempt) {
|
|
469
483
|
entry.lastAt = attempt.at;
|
|
470
484
|
entry.lastOutcome = attempt.outcome;
|
|
@@ -630,6 +644,13 @@ export function createRenewHosting(options = {}) {
|
|
|
630
644
|
// The one-at-a-time and sign-in exclusion guards still apply.
|
|
631
645
|
async function runNow(provider, key) {
|
|
632
646
|
assertAccount(provider, key);
|
|
647
|
+
if (accountBrowserOpen(provider, key)) {
|
|
648
|
+
throw new RenewHostingError(
|
|
649
|
+
"browser_open",
|
|
650
|
+
"Close this account's fingerprint browser before running hosted renewal.",
|
|
651
|
+
409,
|
|
652
|
+
);
|
|
653
|
+
}
|
|
633
654
|
if (startingRun || running || signInBusy() || identityCheckBusy()) {
|
|
634
655
|
throw new RenewHostingError("busy", "A sign-in is already running; try again when it finishes.", 409);
|
|
635
656
|
}
|
|
@@ -642,6 +663,13 @@ export function createRenewHosting(options = {}) {
|
|
|
642
663
|
}
|
|
643
664
|
const check = await eligibility(provider, key);
|
|
644
665
|
if (!check.ok) throw new RenewHostingError(check.code, check.message, check.status);
|
|
666
|
+
if (accountBrowserOpen(provider, key)) {
|
|
667
|
+
throw new RenewHostingError(
|
|
668
|
+
"browser_open",
|
|
669
|
+
"Close this account's fingerprint browser before running hosted renewal.",
|
|
670
|
+
409,
|
|
671
|
+
);
|
|
672
|
+
}
|
|
645
673
|
running = { provider: entry.provider, key: entry.key, startedAt: now(), manual: true };
|
|
646
674
|
void perform(entry, check, { manual: true });
|
|
647
675
|
return { ok: true, running: publicRunning() };
|
|
@@ -701,6 +729,10 @@ export function createRenewHosting(options = {}) {
|
|
|
701
729
|
if (at < expiresAt - lead) continue;
|
|
702
730
|
if (isFiniteNumber(entry.nextDueAt) && at < entry.nextDueAt) continue;
|
|
703
731
|
if (isFiniteNumber(entry.lastAt) && at - entry.lastAt < minGapMs) continue;
|
|
732
|
+
// Skip this due account while its standalone fingerprint browser is
|
|
733
|
+
// open: no fail-streak penalty, no pause, and other due accounts in the
|
|
734
|
+
// loop still proceed.
|
|
735
|
+
if (accountBrowserOpen(entry.provider, entry.key)) continue;
|
|
704
736
|
if (dirty) {
|
|
705
737
|
await save();
|
|
706
738
|
dirty = false;
|
|
@@ -710,6 +742,7 @@ export function createRenewHosting(options = {}) {
|
|
|
710
742
|
await record(entry, { at, outcome: "error", code: check.code, message: check.message });
|
|
711
743
|
continue;
|
|
712
744
|
}
|
|
745
|
+
if (accountBrowserOpen(entry.provider, entry.key)) continue;
|
|
713
746
|
await perform(entry, check, { manual: false });
|
|
714
747
|
return { ran: true, provider: entry.provider, key: entry.key };
|
|
715
748
|
}
|