As of Chrome 134 (2025-03-04), you can now use the closedby="none"
attribute as a native solution to prevent modal from being closed by the Esc key.
<dialog closedby="none" id="myModal">
<h3>Modal Title</h3>
<p>The modal contents.</p>
</dialog>
<button onclick="document.getElementById('myModal').showModal()">Open Modal</button>
More info: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/dialog#closedby