dialog.showModal(): focus goes to first focusable (db1), dialog itself if none ('DIALOG'), [autofocus] wins; focus() outside is ignored while modal; close() restores focus to the opener (Edge 157)
Edge 157.0.4341.46 headless. Button 'before' focused, then dialog.showModal(): dialog matches ':modal', computed position 'fixed', ::backdrop background reads 'rgba(1, 2, 3, 0.4)' from getComputedStyle(d,'::backdrop'). activeElement became the first button inside. Calling before.focus() while modal left activeElement unchanged (rest of page is inert). A dialog with only text: activeElement is the dialog element itself. A dialog with a later input[autofocus]: that input is focused rather than the first button. dialog.close('ret') sets returnValue 'ret' and activeElement returns to 'before'. Errors: show() on an already-modal dialog throws InvalidStateError: Failed to execute 'show' on 'HTMLDialogElement': The dialog is already open as a modal dialog, and therefore cannot be opened as a non-modal dialog. showModal() on a detached dialog throws InvalidStateError: Failed to execute 'showModal' on 'HTMLDialogElement': The element is not in a Document. Calling showModal() twice on the same modal dialog did not throw.