redact-rule-row failed in WebKit zh on a loaded machine with
"locator.scrollIntoViewIfNeeded: Element is not attached to the DOM".
Cause: opening Settings reads the settings twice, the page's own read
(showView) and the window's load() once the state is in, and each read
redraws every row (renderRedact replaces #redactList's children). The
test found the row after the first draw and scrolled it; when the second
read landed during Playwright's stability check, the element it held was
gone. Locator clicks retry on a detached element, but
scrollIntoViewIfNeeded and boundingBox act on the element they found.
A probe wrapping #redactList's replaceChildren showed the two draws
(renderSettings < loadSettings, then the same < async load).
Fix: reader.cjs gains watchSettingsReads (an init script counting the
page's GET /api/settings reads, each counted drawn a task after its body
is read, after loadSettings has drawn from it) and settingsDrawn (waits
for load.done, which load() sets in the same run that then asks for the
settings, and for every read asked to be drawn). redact-rule-row and its
two siblings on the same rows, redact-rule-edit and redact-kinds, wait
for it after finding their first row. The page is unchanged: its second
draw is how Settings catches up with the state.
Run (injected: the test's route holds the page's second settings read
until the row is found, and lets it go as the test acts on it):
- Injected, without the wait: 8 of 8 red in Chromium and WebKit, en and
zh, 1100 and 640px, the issue's exact error. With the wait: 8 of 8
green.
- redact-rule-row WebKit, 25 runs: 100 of 100 cases green at load ~115.
- redact-rule-row, redact-rule-edit and redact-kinds in both engines:
50 of 50, and again 50 of 50 (injected 8 of 8) after rebasing
onto 18e82adc6.
Not done here: 37 other Settings tests use boundingBox or
scrollIntoViewIfNeeded after finding a row and can meet the same second
draw; #1659 lists them, to move onto settingsDrawn.
67 lines
3.1 KiB
JavaScript
67 lines
3.1 KiB
JavaScript
// The app deliberately undoes unsolicited scrollIntoView (including Playwright's
|
|
// automatic scroll). Bring a control into sight with real wheel input first.
|
|
// Wholly in sight: one cut off by a fraction of a pixel at the view's foot
|
|
// was scrolled the rest of the way by Playwright's click itself, before the
|
|
// app saw the click, and the page moved 1px under it (860 to 861 on the
|
|
// Usage page's Fetch from archive, once the archive switch in its header
|
|
// had moved the rows 4px down).
|
|
async function inView(page, locator) {
|
|
await locator.waitFor({state:"visible"});
|
|
if (await locator.evaluate(e => !e.closest("#view-usage"))) return;
|
|
const view = page.locator("#view-usage");
|
|
const v = await view.boundingBox();
|
|
await page.mouse.move(v.x + v.width / 2, v.y + v.height / 2);
|
|
for (let i = 0; i < 80; i++) {
|
|
const b = await locator.boundingBox();
|
|
if (!b) { await page.waitForTimeout(40); continue; }
|
|
// one taller than the view: its top in sight
|
|
if (b.y >= v.y && (b.y + b.height <= v.y + v.height || (b.height > v.height && b.y < v.y + v.height))) {
|
|
await page.waitForTimeout(300);
|
|
return;
|
|
}
|
|
const delta = b.y < v.y ? -20 : 20;
|
|
await page.mouse.wheel(0, delta);
|
|
await page.waitForTimeout(40);
|
|
}
|
|
throw new Error("control did not come into sight: " + JSON.stringify({view:v,target:await locator.boundingBox(),scroll:await view.evaluate(e=>e.scrollTop)}));
|
|
}
|
|
|
|
async function click(page, locator) {
|
|
await inView(page, locator);
|
|
await locator.click();
|
|
}
|
|
|
|
// Settings is drawn from each read of the settings, and opening the page
|
|
// reads them twice: the page's own read, then the window's load() once the
|
|
// state is in. Every row is replaced by the second draw, so a row found
|
|
// after the first is detached under whatever the test does to it next
|
|
// (#1653: scrollIntoViewIfNeeded in WebKit on a busy machine). Call
|
|
// watchSettingsReads before page.goto; settingsDrawn then waits until load()
|
|
// has asked for its read and every read asked for has been drawn.
|
|
async function watchSettingsReads(page) {
|
|
await page.addInitScript(() => {
|
|
const reads = window.__settingsReads = { asked: 0, drawn: 0 };
|
|
const fetch0 = window.fetch;
|
|
window.fetch = function (input, init) {
|
|
const p = fetch0.apply(this, arguments);
|
|
const url = new URL(typeof input === "string" ? input : input.url, location.href);
|
|
if (url.pathname !== "/api/settings" || (init?.method || "GET") !== "GET") return p;
|
|
reads.asked++;
|
|
// drawn a task after its body is in: loadSettings draws in the
|
|
// microtasks that follow
|
|
const drawn = () => setTimeout(() => reads.drawn++);
|
|
return p.then((res) => {
|
|
const text = res.text;
|
|
res.text = function () { return text.call(this).finally(drawn); };
|
|
return res;
|
|
}, (e) => { drawn(); throw e; });
|
|
};
|
|
});
|
|
}
|
|
|
|
// load.done is set in the same run of load() that then asks for the
|
|
// settings, with no wait between, so once it is set the read is counted.
|
|
const settingsDrawn = (page) => page.waitForFunction(() => load.done && __settingsReads.asked === __settingsReads.drawn);
|
|
|
|
module.exports = { inView, click, watchSettingsReads, settingsDrawn };
|