fix(agent): bound push suppression to observed browser attention
This commit is contained in:
@@ -108,6 +108,20 @@ try {
|
||||
assert.equal(sessionPaths.length, 2);
|
||||
const secondPath = sessionPaths.find(path => !path.endsWith(firstSession));
|
||||
await expectEventually(() => requests.some(request => request.path === secondPath && request.body?.focused === true));
|
||||
// Playwright forces every target focused/visible. Supply controlled DOM state
|
||||
// to exercise the production reporter's blur/visibility wiring deterministically.
|
||||
const beforeBlur = requests.length;
|
||||
await page.evaluate(() => {
|
||||
Object.defineProperty(document, "hasFocus", { configurable: true, value: () => false });
|
||||
window.dispatchEvent(new Event("blur"));
|
||||
});
|
||||
await expectEventually(() => requests.slice(beforeBlur).some(request => request.path.endsWith(firstSession) && request.body?.visibility === "visible" && request.body?.focused === false));
|
||||
await page.evaluate(() => {
|
||||
Object.defineProperty(document, "hidden", { configurable: true, value: true });
|
||||
document.dispatchEvent(new Event("visibilitychange"));
|
||||
});
|
||||
await expectEventually(() => requests.slice(beforeBlur).some(request => request.path.endsWith(firstSession) && request.body?.visibility === "hidden" && request.body?.focused === false));
|
||||
await page.evaluate(() => { delete document.hasFocus; delete document.hidden; window.dispatchEvent(new Event("focus")); });
|
||||
await second.getByRole("textbox").first().click();
|
||||
await second.getByRole("textbox").first().pressSequentially("interaction");
|
||||
await expectEventually(() => requests.some(request => request.path === secondPath && request.body?.interacted === true));
|
||||
@@ -116,6 +130,11 @@ try {
|
||||
assert.deepEqual(sequences, [...new Set(sequences)].sort((a, b) => a - b));
|
||||
}
|
||||
await page.bringToFront();
|
||||
const beforeHide = requests.length;
|
||||
await page.evaluate(() => window.dispatchEvent(new Event("pagehide")));
|
||||
await expectEventually(() => requests.slice(beforeHide).some(request => request.path.endsWith(firstSession) && request.body?.visibility === "hidden" && request.body?.focused === false));
|
||||
await page.evaluate(() => window.dispatchEvent(new Event("pageshow")));
|
||||
await expectEventually(() => requests.slice(beforeHide).some(request => request.path.endsWith(firstSession) && request.body?.visibility === "visible" && request.body?.focused === true));
|
||||
const worker = context.serviceWorkers().find(worker => new URL(worker.url()).pathname === "/sw.js");
|
||||
assert.ok(worker, "actual service worker activated");
|
||||
const push = async cursor => worker.evaluate(async ({ cursor, sourceId }) => {
|
||||
|
||||
Reference in New Issue
Block a user