The focus trap solution would of course require a focusable element inside each iframe to ensure it works, which isn’t ideal.
I’ve created another work-around that will return focus to the active iframe if you tab out of it.
document.addEventListener("keydown", function() {
console.log("active", document.activeElement.tagName)
citFrames[focusStack[focusStack.length - 1]].contentWindow.focus();
})
This is of course very primitive but it’s a small proof of concept to at least keep the active iframe as the focus target.
The above event will only fire when the iframe focus has been escaped.
I also tried attaching an onfocus listener to the body tag but it isn’t fired via tab focus for some reason. May investigate further on that because that would be the most ideal solution.