Scripts may close only the windows that were opened by them.
// You can only close a window that your script made, so this is possible:
window.open("", "_blank", "");
window.close();
// But otherwise you can change the link, like that:
location.href = "https://bruh.io";
// Make sure that you have https://