You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
3.8 KiB

6 days ago
// 蓝湖 Axure 嗅探 v2:txt Cookie → SSO 刷新 → 二次导航直达文档 → 全量抓包
import { chromium } from 'file:///C:/Users/Administrator/AppData/Roaming/npm/node_modules/@star_work/lanhu-mcp/node_modules/playwright/index.mjs';
import fs from 'node:fs';
const TID = 'b013dded-642f-4899-b829-daa5c093fdf0';
const PID = 'e528bb49-1eea-4d76-b7e0-4055bc7c1b70';
const DOC_ID = 'bade4454-52aa-44db-8ba2-dec594732ecb';
const DOC_URL = `https://lanhuapp.com/web/#/item/project/product?tid=${TID}&pid=${PID}&image_id=${DOC_ID}&docId=${DOC_ID}&docType=axure&versionId=c461813e-2c49-4bcc-8602-babcaf14c3bb&pageId=d5f02e7baf3e4f02a3ab5c02ed25eb15&parentId=0a6bd20e-247e-4a19-8e88-784b8aff92cc`;
const raw = fs.readFileSync('e:/code/crm-backend-matt/.scratch/opportunity-e2e/原型及蓝湖cookie.txt', 'utf8');
const cookieLine = raw.split('\n').find(l => l.startsWith('Cookie:') || l.startsWith('Cookie:')) || raw.split('\n')[1];
const cookieStr = cookieLine.replace(/^Cookie[::]\s*/, '').trim();
const pairs = cookieStr.split(';').map(s => s.trim()).filter(Boolean).map(s => {
const i = s.indexOf('='); return { name: s.slice(0, i), value: s.slice(i + 1) };
});
const browser = await chromium.launch({ headless: false });
const context = await browser.newContext({
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36',
viewport: { width: 1720, height: 1080 },
});
await context.addCookies(pairs.map(p => ({ name: p.name, value: p.value, domain: '.lanhuapp.com', path: '/' })));
const page = await context.newPage();
const log = [];
page.on('response', async (resp) => {
const url = resp.url();
if (/hm\.baidu|arms-retcode|aliyuncs|acjs\.aliyun/.test(url)) return; // 噪音
const entry = { url: url.slice(0, 500), status: resp.status(), method: resp.request().method() };
try {
const ct = resp.headers()['content-type'] || '';
entry.ct = ct.split(';')[0];
if (ct.includes('json')) {
const body = await resp.text();
entry.body = body.length > 20000 ? body.slice(0, 20000) + '...<truncated>' : body;
}
} catch { }
log.push(entry);
});
console.log('[1] first nav (SSO refresh) ...');
await page.goto(DOC_URL, { waitUntil: 'domcontentloaded', timeout: 60000 });
await page.waitForTimeout(12000);
console.log('[2] second nav (direct to doc) ...');
await page.goto(DOC_URL, { waitUntil: 'domcontentloaded', timeout: 60000 });
await page.waitForTimeout(20000);
// 若仍在文档列表页,尝试点击目标文档
const bodyText = await page.evaluate(() => document.body.innerText).catch(() => '');
if (bodyText.includes('web端 V1.0') && !bodyText.includes('页面')) {
console.log('[3] on doc list, clicking target doc ...');
const el = page.locator('text=【原型】itc信息化业务中台web端').first();
await el.click({ timeout: 10000 }).catch(e => console.log(' click failed:', e.message));
await page.waitForTimeout(20000);
}
const finalText = await page.evaluate(() => document.body.innerText).catch(() => '(failed)');
fs.mkdirSync('e:/code/crm-backend-matt/.scratch/lanhu-latest', { recursive: true });
fs.writeFileSync('e:/code/crm-backend-matt/.scratch/lanhu-latest/network-log-v2.json', JSON.stringify(log, null, 2), 'utf8');
fs.writeFileSync('e:/code/crm-backend-matt/.scratch/lanhu-latest/page-dump-v2.txt', finalText, 'utf8');
await context.storageState({ path: 'e:/code/crm-backend-matt/.scratch/lanhu-latest/storage-state.json' });
console.log('captured:', log.length, 'requests');
console.log('=== lanhuapp api urls ===');
for (const e of log.filter(e => e.url.includes('lanhuapp.com'))) {
console.log(' ', e.status, e.method, e.ct || '', e.url.slice(0, 180));
}
console.log('=== page text (first 800 chars) ===');
console.log(finalText.slice(0, 800));
await browser.close();