mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-12-01 21:05:42 +09:00
fix: Correlate intercepted Form responses to the submission
This commit is contained in:
1 parent
34b6fbb85e
commit
de2f4edef6
2 files changed
+61
-1
No files matched your search
@@ -956,6 +956,7 @@ const createManagedFormSocket = ({
|
||||
navigationGap = false,
|
||||
fastRedirect = false,
|
||||
interceptedBodyUnreadable = false,
|
||||
interceptedChild = false,
|
||||
unrelated,
|
||||
}: {
|
||||
body?: string;
|
||||
@@ -965,6 +966,7 @@ const createManagedFormSocket = ({
|
||||
navigationGap?: boolean | "stalled";
|
||||
fastRedirect?: boolean;
|
||||
interceptedBodyUnreadable?: boolean;
|
||||
interceptedChild?: boolean;
|
||||
unrelated?: { method: string; url: string; frameId: string };
|
||||
} = {}) => {
|
||||
const url = "http://127.0.0.1:5173/contact";
|
||||
@@ -1018,7 +1020,15 @@ const createManagedFormSocket = ({
|
||||
id: message.id,
|
||||
...(interceptedBodyUnreadable
|
||||
? { error: { code: -32000, message: "Body unavailable" } }
|
||||
: { result: { body, base64Encoded } }),
|
||||
: {
|
||||
result: {
|
||||
body:
|
||||
message.params?.requestId === "intercepted-child"
|
||||
? JSON.stringify({ results: [{ status: 418 }] })
|
||||
: body,
|
||||
base64Encoded,
|
||||
},
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
0
|
||||
@@ -1112,12 +1122,34 @@ const createManagedFormSocket = ({
|
||||
if (fastRedirect) {
|
||||
emit("Fetch.requestPaused", {
|
||||
requestId: "intercepted-managed",
|
||||
networkId: "managed",
|
||||
frameId: "main",
|
||||
responseStatusCode: 200,
|
||||
request: {
|
||||
method: "POST",
|
||||
url: "http://127.0.0.1:5173/__ws-form/contact",
|
||||
},
|
||||
});
|
||||
if (interceptedChild) {
|
||||
emit("Network.requestWillBeSent", {
|
||||
requestId: "child",
|
||||
frameId: "child",
|
||||
request: {
|
||||
method: "POST",
|
||||
url: "http://127.0.0.1:5173/__ws-form/contact",
|
||||
},
|
||||
});
|
||||
emit("Fetch.requestPaused", {
|
||||
requestId: "intercepted-child",
|
||||
networkId: "child",
|
||||
frameId: "child",
|
||||
responseStatusCode: 200,
|
||||
request: {
|
||||
method: "POST",
|
||||
url: "http://127.0.0.1:5173/__ws-form/contact",
|
||||
},
|
||||
});
|
||||
}
|
||||
} else {
|
||||
emit("Network.loadingFinished", { requestId: "managed" });
|
||||
navigated = true;
|
||||
@@ -1211,6 +1243,27 @@ test("captures managed Form results before a fast redirect discards the network
|
||||
}
|
||||
});
|
||||
|
||||
test("ignores an intercepted child-frame Form response", async () => {
|
||||
const { socket, counters } = createManagedFormSocket({
|
||||
fastRedirect: true,
|
||||
interceptedChild: true,
|
||||
});
|
||||
const session = await createFormBrowserSession(socket);
|
||||
try {
|
||||
const result = await session.submitForm!({
|
||||
url: "http://127.0.0.1:5173/contact",
|
||||
selector: "form",
|
||||
values: [],
|
||||
timeout: 1000,
|
||||
});
|
||||
expect(result.results).toEqual([{ status: 201, resourceId: "action" }]);
|
||||
expect(counters.interceptedReads).toBe(1);
|
||||
expect(counters.continuedResponses).toBe(2);
|
||||
} finally {
|
||||
await session.close();
|
||||
}
|
||||
});
|
||||
|
||||
test("continues a fast redirect when its intercepted response body cannot be read", async () => {
|
||||
const { socket, counters } = createManagedFormSocket({
|
||||
fastRedirect: true,
|
||||
|
||||
@@ -2561,6 +2561,13 @@ const submitFormWithBrowserRuntime = async (
|
||||
}
|
||||
const requestId = params.requestId;
|
||||
if (
|
||||
dispatchStarted &&
|
||||
mainFrameId !== undefined &&
|
||||
"frameId" in params &&
|
||||
params.frameId === mainFrameId &&
|
||||
"networkId" in params &&
|
||||
typeof params.networkId === "string" &&
|
||||
submissionRequestIds.has(params.networkId) &&
|
||||
"responseStatusCode" in params &&
|
||||
typeof params.responseStatusCode === "number" &&
|
||||
"request" in params &&
|
||||
|
||||
Reference in new issue
Block a user