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.
 
 
 
 
 
 

59 lines
3.1 KiB

// 蓝湖 Axure 文档嗅探:注入 Cookie → 打开文档页 → 记录全部 /api/ 请求与响应
// 产出:.scratch/lanhu-latest/network-log.json(供后续直接 HTTP 复用 API)
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 DOC_URL = 'https://lanhuapp.com/web/#/item/project/product?tid=b013dded-642f-4899-b829-daa5c093fdf0&pid=e528bb49-1eea-4d76-b7e0-4055bc7c1b70&image_id=bade4454-52aa-44db-8ba2-dec594732ecb&docId=bade4454-52aa-44db-8ba2-dec594732ecb&docType=axure&versionId=c461813e-2c49-4bcc-8602-babcaf14c3bb&pageId=d5f02e7baf3e4f02a3ab5c02ed25eb15&parentId=0a6bd20e-247e-4a19-8e88-784b8aff92cc';
// 1. 读 Cookie
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) };
});
console.log('cookie pairs:', pairs.map(p => p.name).join(','));
// 2. 起浏览器(可见,降低风控概率)
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: 1600, height: 1000 },
});
await context.addCookies(pairs.map(p => ({ name: p.name, value: p.value, domain: '.lanhuapp.com', path: '/' })));
const page = await context.newPage();
// 3. 记录所有 API 请求
const log = [];
page.on('response', async (resp) => {
const url = resp.url();
if (!url.includes('/api') && !url.includes('axure')) return;
const entry = { url, status: resp.status(), method: resp.request().method() };
try {
const ct = resp.headers()['content-type'] || '';
if (ct.includes('json')) {
const body = await resp.text();
entry.body = body.length > 8000 ? body.slice(0, 8000) + '...<truncated>' : body;
}
} catch { /* body 不可读则跳过 */ }
log.push(entry);
});
console.log('navigating ...');
await page.goto(DOC_URL, { waitUntil: 'domcontentloaded', timeout: 60000 });
// 等页面树渲染
await page.waitForTimeout(15000);
// 4. dump 左侧页面树文本 + 整页可见文本
const treeText = await page.evaluate(() => document.body.innerText).catch(() => '(evaluate 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.json', JSON.stringify(log, null, 2), 'utf8');
fs.writeFileSync('e:/code/crm-backend-matt/.scratch/lanhu-latest/page-dump.txt', treeText, 'utf8');
console.log('API calls captured:', log.length);
console.log('sample urls:');
for (const e of log.slice(0, 40)) console.log(' ', e.status, e.method, e.url.slice(0, 160));
await browser.close();