fix(settings): complete DingTalk scan login flow
This commit is contained in:
@@ -172,18 +172,25 @@ async function startSession(id, space) {
|
||||
scheduleCleanup(s);
|
||||
};
|
||||
|
||||
page.on("request", (request) => {
|
||||
const captureRequest = async (request) => {
|
||||
const url = request.url();
|
||||
if (!url.includes("dingtalk.com")) return;
|
||||
const h = request.headers();
|
||||
if (!h["a-token"] || !h.cookie || capturedHeaders) return;
|
||||
// Playwright request.headers() intentionally omits security-related
|
||||
// headers on some Chromium builds, notably Cookie. allHeaders() is the
|
||||
// complete API and is required for the capture consumed by the scanner.
|
||||
const h = await request.allHeaders().catch(() => request.headers());
|
||||
if (capturedHeaders) return;
|
||||
if (!h["a-token"] || !h.cookie) return;
|
||||
capturedHeaders = { ...h };
|
||||
delete capturedHeaders["content-length"];
|
||||
delete capturedHeaders["accept-encoding"];
|
||||
delete capturedHeaders["host"];
|
||||
s.state = s.state === "qr" ? "scanned" : "reusing";
|
||||
finish(capturedHeaders);
|
||||
});
|
||||
};
|
||||
// Login may redirect the original tab or open another page. Listening on
|
||||
// the whole context keeps credential capture alive across both paths.
|
||||
context.on("request", captureRequest);
|
||||
|
||||
// Read the QR directly from DingTalk's canvas. Do NOT screenshot the DOM:
|
||||
// Playwright element screenshots on a high-DPR page can apply the crop in
|
||||
@@ -226,7 +233,21 @@ async function startSession(id, space) {
|
||||
await page.goto(SCAN_URL(space), { waitUntil: "domcontentloaded", timeout: 45000 }).catch(() => {});
|
||||
|
||||
if (page.url().includes("login.dingtalk.com") && !capturedHeaders) {
|
||||
s.qrPng = await grabQR();
|
||||
// The canvas is rendered after DOMContentLoaded. Keep the public state at
|
||||
// starting until a real QR exists so the UI shows its generation loader,
|
||||
// never an empty "please scan" panel.
|
||||
const qrReadyDeadline = Date.now() + 20000;
|
||||
while (!capturedHeaders && !s.qrPng && Date.now() < qrReadyDeadline) {
|
||||
s.qrPng = await grabQR();
|
||||
if (!s.qrPng) await new Promise((resolve) => setTimeout(resolve, 400));
|
||||
}
|
||||
if (capturedHeaders) return;
|
||||
if (!s.qrPng) {
|
||||
s.state = "failed";
|
||||
s.error = "qr_generation_failed";
|
||||
scheduleCleanup(s);
|
||||
return;
|
||||
}
|
||||
s.state = "qr";
|
||||
const deadline = Date.now() + QR_TTL_MS;
|
||||
const regrab = setInterval(async () => {
|
||||
|
||||
Reference in New Issue
Block a user