navigate multiple pages in Chrome Console

I have some code which clicks through a website and downloads some data. But when I try to run it in chrome console, as soon as the browser navigates to the next website, the code halts.
How can I fix this?

document.getElementById("LOB").value="CA"
document.getElementById("LOB_State").value="MI"
document.getElementById("Effective_Range").value="0"
document.getElementById("Effective_Month").value="12"
document.getElementById("Effective_Day").value="1"
document.getElementById("Effective_Year").value="2024"
fillTables()
   
//wait for page to load
    
document.getElementsByName("File")[1].checked = true
document.getElementsByName("submitButton")[0].click()

Code can’t get past here because the ‘click’ causes a new page to load.

//wait for page to load
    
document.getElementById("downloadbutton").click()
document.getElementsByClassName("buttons")[3].click()
    
//wait for page to load