Found in phetsims/vector-addition#442. A Display in an iframe can fail to receive focus events. If the parent window is active (has focus), focus cannot be set programmatically in the iframe Display and focus events are not dispatched at all.
To reproduce the problem
- Run a PhET simulation in an iframe.
- Click or focus something in the parent window (outside of the iframe Display).
- Now observe that scripted calls to
node.focus() do nothing, and event listeners on focus events never fire.
We will have to be careful with this. We do not want to steal focus from the parent window, that will annoy the parent application and make it more difficult for people to embed scenery Displays in iframes. However, it seems fair to move focus into the iframe window when it receives input. And I am worried about problems that could occur when we do not consistently get focus events.
Found in phetsims/vector-addition#442. A Display in an iframe can fail to
receivefocus events. If the parent window is active (has focus), focus cannot be set programmatically in the iframe Display andfocusevents are not dispatched at all.To reproduce the problem
node.focus()do nothing, and event listeners onfocusevents never fire.We will have to be careful with this. We do not want to steal focus from the parent window, that will annoy the parent application and make it more difficult for people to embed scenery Displays in iframes. However, it seems fair to move focus into the iframe window when it receives input. And I am worried about problems that could occur when we do not consistently get focus events.