fix(browser): preserve captures when response bodies are unavailable
This commit is contained in:
@@ -7,6 +7,13 @@ export async function startBrowserVerifierSite() {
|
||||
let port = 0;
|
||||
let sessionGeneration = 0;
|
||||
const server = createServer((request, response) => {
|
||||
if (request.url === "/slow-json") {
|
||||
response.setHeader("content-type", "application/json");
|
||||
response.write('{"pending":');
|
||||
const timer = setTimeout(() => response.end("true}"), 350);
|
||||
response.once("close", () => clearTimeout(timer));
|
||||
return;
|
||||
}
|
||||
if (request.url === "/screenshot-noise") {
|
||||
response.setHeader("content-type", "text/html");
|
||||
response.end(`<!doctype html><html><body style="margin:0"><canvas width="2048" height="1536"></canvas><script>
|
||||
@@ -174,6 +181,11 @@ const browserScript = (port) => `
|
||||
},
|
||||
body: JSON.stringify({ token: "request-body-secret-value", active: true })
|
||||
});
|
||||
fetch("/slow-json", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ pending: true })
|
||||
});
|
||||
const socket = new WebSocket("ws://127.0.0.1:${String(port)}/live?token=websocket-url-secret");
|
||||
socket.addEventListener("open", () => socket.send(JSON.stringify({ token: "websocket-secret-value" })));
|
||||
socket.addEventListener("message", () => socket.close());
|
||||
|
||||
@@ -217,6 +217,19 @@ export function assertSensitiveShapes(result) {
|
||||
);
|
||||
if (request === undefined)
|
||||
throw new Error("Real Chrome JSON request/response shapes were missing");
|
||||
if (
|
||||
!result.network.requests.some(
|
||||
(item) =>
|
||||
item.url.endsWith("/slow-json") &&
|
||||
item.body_shapes.status === "partial" &&
|
||||
item.body_shapes.request !== null &&
|
||||
item.body_shapes.response === null,
|
||||
) ||
|
||||
!result.completeness.unavailable_sections.includes("json_body_shapes")
|
||||
)
|
||||
throw new Error(
|
||||
"Real Chrome unfinished JSON bodies were not reported as unavailable",
|
||||
);
|
||||
const consoleText = result.console.events.flatMap(
|
||||
(event) => event.text_capture.values,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user