How to determine if a dashboard tab is active

I think a Ui-template script would do this, then use a switch node and context storage to stop flow progression.
e.g.

[{"id":"d696313000561a90","type":"inject","z":"65617ffeb779f51c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":194.00000762939453,"y":2340.000069618225,"wires":[["1302ef8b43047b4e"]]},{"id":"1302ef8b43047b4e","type":"switch","z":"65617ffeb779f51c","name":"","property":"focus","propertyType":"flow","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":354.00000762939453,"y":2340.000069618225,"wires":[["50a3860f84f41d3e","5b1974eeda2e6c33"]]},{"id":"50a3860f84f41d3e","type":"debug","z":"65617ffeb779f51c","name":"debug 260","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":534.0000076293945,"y":2340.000069618225,"wires":[]},{"id":"5b1974eeda2e6c33","type":"ui_text","z":"65617ffeb779f51c","group":"2d4fe667.28f8ba","order":20,"width":0,"height":0,"name":"","label":"messages pass when this page is in focus","format":"{{msg.payload}}","layout":"row-spread","className":"","x":524.0000076293945,"y":2380.000069618225,"wires":[]},{"id":"4bc90f993b0ad16e","type":"ui_template","z":"65617ffeb779f51c","group":"2d4fe667.28f8ba","name":"","order":21,"width":0,"height":0,"format":"<script>\n(function(scope) {\n    document.addEventListener(\"visibilitychange\", function (event) {\n        scope.send({payload: !document.hidden});\n    });\n})(scope);\n</script>","storeOutMessages":false,"fwdInMessages":false,"resendOnRefresh":true,"templateScope":"local","className":"","x":160,"y":2460,"wires":[["f7ad3a5227307fb5","1bc41ac7b88d7fc3"]]},{"id":"f7ad3a5227307fb5","type":"debug","z":"65617ffeb779f51c","name":"debug 259","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":370,"y":2440,"wires":[]},{"id":"1bc41ac7b88d7fc3","type":"change","z":"65617ffeb779f51c","name":"","rules":[{"t":"set","p":"focus","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":2480,"wires":[[]]},{"id":"2d4fe667.28f8ba","type":"ui_group","name":"demo","tab":"1caa8458.b17814","order":2,"disp":true,"width":"12","collapse":false},{"id":"1caa8458.b17814","type":"ui_tab","name":"Demo","icon":"dashboard","order":1,"disabled":false,"hidden":false}]
<script>
(function(scope) {
    document.addEventListener("visibilitychange", function (event) {
        scope.send({payload: !document.hidden});
    });
})(scope);
</script>

[edit] more concise.