Skip to content

176 web animation techniques, each a live demo with plain settings and a ready-made prompt for your AI assistant. No dependencies, no build step.

docs: say that a page's own focus() counts as the visitor's, listen for focusin in the capture phase, and name the dispatched-events test for what it covers

matin327d12f24616
diff --git a/assets/js/demo-page.js b/assets/js/demo-page.js
index ef83f7b0..3b36156e 100644
--- a/assets/js/demo-page.js
+++ b/assets/js/demo-page.js
@@ -356,7 +356,9 @@
// can stop a Show me run that is under way and leave the visitor in control. Click is there for an activation that comes
// with no pointer or key event (assistive technology); a press sends one for the press and then one for the click.
// The same input, or focus arriving in the stage (a Tab into a field), also means the visitor got there before the Show me
- // press on arrival, and that press is then skipped, so it cannot wipe or replace what they are doing.
+ // press on arrival, and that press is then skipped, so it cannot wipe or replace what they are doing. Focus counts whoever
+ // asks for it: a page's own focus() call makes a trusted focusin in Chrome too, so a do-it page must not move focus into
+ // its stage before that press (none does).
var visitorActed = false;
function setUpVisitorInput() {
['pointerdown', 'keydown', 'wheel', 'touchstart', 'click'].forEach(function (type) {
@@ -366,7 +368,7 @@
doc.dispatchEvent(new win.CustomEvent('hb:input', { detail: { type: type } }));
}, { capture: true, passive: true });
});
- stage.addEventListener('focusin', function (e) { if (e.isTrusted) visitorActed = true; });
+ stage.addEventListener('focusin', function (e) { if (e.isTrusted) visitorActed = true; }, { capture: true, passive: true });
}
// Scroll pages: Play scrolls the box from where it is to its end at a steady speed (the whole box in about six
diff --git a/tests/demo-page.test.js b/tests/demo-page.test.js
index 898c37ce..20bb516e 100644
--- a/tests/demo-page.test.js
+++ b/tests/demo-page.test.js
@@ -164,7 +164,8 @@ test('the Show me press on arrival is skipped after focus arrives in the stage,
assert.equal(page.sent.length, 0);
});
-test('input and focus that the page made itself do not count as the visitor acting', () => {
+// Only dispatched events can be tried here: a real focus() call makes a trusted focusin, which does count.
+test('events dispatched by script (isTrusted false) do not count as the visitor acting', () => {
const page = standInPage('do', false);
for (const type of ['pointerdown', 'keydown', 'wheel', 'touchstart', 'click', 'focusin']) page.stage.emit(type, script);
page.runTimers();