feat(daemon): add stealth injection orchestrator (Task 17)
- Create stealth/index.ts: applyStealth() calls all 6 injection modules in correct order (initScript before nav, page.route after page) - Update browser-manager.ts: call applyStealth in createPage before goto - Constructor now accepts profileId (default 'desktop-chrome') or profile object - Update daemon src/index.ts: re-export stealth orchestrator, getProfile, humanClick, humanType, humanScroll, injectHeaderStealth
This commit is contained in:
@@ -4,6 +4,8 @@ import StealthPlugin from 'puppeteer-extra-plugin-stealth';
|
||||
import type { Browser, BrowserContext, Page } from 'playwright';
|
||||
import type { FingerprintProfile, PageInfo } from '@visionl/core';
|
||||
import { PageRegistry } from './page-registry.js';
|
||||
import { getProfile } from './stealth/profiles/index.js';
|
||||
import { applyStealth } from './stealth/index.js';
|
||||
|
||||
// Apply stealth plugin once at module level / 模块级别一次性注入隐身插件
|
||||
chromium.use(StealthPlugin());
|
||||
@@ -18,8 +20,14 @@ export class BrowserManager {
|
||||
private registry = new PageRegistry();
|
||||
private profile: FingerprintProfile;
|
||||
|
||||
constructor(profile: FingerprintProfile) {
|
||||
this.profile = profile;
|
||||
constructor(profileOrId: FingerprintProfile | string = 'desktop-chrome') {
|
||||
if (typeof profileOrId === 'string') {
|
||||
const resolved = getProfile(profileOrId);
|
||||
if (!resolved) throw new Error(`Unknown profile: ${profileOrId}`);
|
||||
this.profile = resolved;
|
||||
} else {
|
||||
this.profile = profileOrId;
|
||||
}
|
||||
}
|
||||
|
||||
async init(): Promise<void> {
|
||||
@@ -61,6 +69,10 @@ export class BrowserManager {
|
||||
});
|
||||
|
||||
const page = await context.newPage();
|
||||
|
||||
// Apply stealth injections before navigation / 导航前注入隐身模块
|
||||
await applyStealth(context, page, this.profile);
|
||||
|
||||
await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||||
const title = await page.title();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user