Just use keyup instead:
document.addEventListener("keyup", e => {
if (e.key === '/') document.getElementById("box").select()
});
Edit:
Reason: The KeyboardEvent.key event follows a sequence in the execution of the different types of events:
keydown
beforeinput (only on editable content like <input>, <textarea>, etc.)
input (only on editable content like <input>, <textarea>, etc.)
keyup
See KeyboardEvent sequence for further details.
So the thing that happens when using keydown in your scenario is:
keydown: box gets selected
beforeinput: fires because the active element is an editable element, but nothing happens
input: fires because the active element is an editable element + inserting the / into box
keyup: fires but nothing happens
When using keyup instead:
keydown: fires but nothing happens
beforeinput: doesn't fire because the active element is NOT an editable element
input: doesn't fire because the active element is NOT an editable element
keyup: box gets selected
Edit: If you want to be able to use / inside the box, first check that box is not the active element (although it would make it impossible to use / in other input's, but I think this is a completely different topic):
document.addEventListener("keyup", e => {
const box = document.getElementById("box")
if (e.key === '/' && box !== document.activeElement) box.select()
});