mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-12 20:15:40 +00:00
test(browser): 扩展 network interception harness
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
1 parent
e0b58ee162
commit
68b56839db
1 file changed
+60
@@ -100,6 +100,20 @@ type MockEvalPlan = Record<
|
|||||||
}
|
}
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
type MockInterceptRuleMatch = {
|
||||||
|
url: string;
|
||||||
|
method: string;
|
||||||
|
resourceType?: string;
|
||||||
|
requestId?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type MockInterceptState = {
|
||||||
|
pausedRequests?: MockInterceptRuleMatch[];
|
||||||
|
continuedRequestIds?: string[];
|
||||||
|
failedRequests?: Array<{ requestId: string; errorReason?: string }>;
|
||||||
|
fetchEnabledPatterns?: unknown[];
|
||||||
|
};
|
||||||
|
|
||||||
type MockPageState = {
|
type MockPageState = {
|
||||||
id: string;
|
id: string;
|
||||||
title: string;
|
title: string;
|
||||||
@@ -116,6 +130,7 @@ type MockPageState = {
|
|||||||
frames?: MockFrameState[];
|
frames?: MockFrameState[];
|
||||||
shadowRoots?: MockShadowRootState[];
|
shadowRoots?: MockShadowRootState[];
|
||||||
events?: MockPageEventPlan;
|
events?: MockPageEventPlan;
|
||||||
|
intercept?: MockInterceptState;
|
||||||
screenshot?: {
|
screenshot?: {
|
||||||
expectedClip?: {
|
expectedClip?: {
|
||||||
x: number;
|
x: number;
|
||||||
@@ -667,6 +682,51 @@ function createMockBrowser(pagesInput: MockPageState[]) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (message.method === 'Fetch.enable') {
|
||||||
|
page.intercept = page.intercept || {};
|
||||||
|
page.intercept.fetchEnabledPatterns = Array.isArray(message.params?.patterns)
|
||||||
|
? (message.params?.patterns as unknown[])
|
||||||
|
: [];
|
||||||
|
reply({});
|
||||||
|
for (const [index, paused] of (page.intercept.pausedRequests || []).entries()) {
|
||||||
|
setTimeout(() => {
|
||||||
|
socket.send(
|
||||||
|
JSON.stringify({
|
||||||
|
method: 'Fetch.requestPaused',
|
||||||
|
params: {
|
||||||
|
requestId: paused.requestId || `fetch-${index + 1}`,
|
||||||
|
resourceType: paused.resourceType || 'XHR',
|
||||||
|
request: {
|
||||||
|
url: paused.url,
|
||||||
|
method: paused.method,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}, 10 + index * 10);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message.method === 'Fetch.continueRequest') {
|
||||||
|
page.intercept = page.intercept || {};
|
||||||
|
page.intercept.continuedRequestIds = page.intercept.continuedRequestIds || [];
|
||||||
|
page.intercept.continuedRequestIds.push(String(message.params?.requestId || ''));
|
||||||
|
reply({});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message.method === 'Fetch.failRequest') {
|
||||||
|
page.intercept = page.intercept || {};
|
||||||
|
page.intercept.failedRequests = page.intercept.failedRequests || [];
|
||||||
|
page.intercept.failedRequests.push({
|
||||||
|
requestId: String(message.params?.requestId || ''),
|
||||||
|
errorReason: typeof message.params?.errorReason === 'string' ? message.params.errorReason : '',
|
||||||
|
});
|
||||||
|
reply({});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (message.method !== 'Runtime.evaluate') {
|
if (message.method !== 'Runtime.evaluate') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user