This post is of help:

Steps:

  1. Open the inspector view by typing Ctrl+ Shift + i and then clicking on console tab at top.
  2. Paste the below code snippet at bottom of console and hit enter
function ClickConnect(){
console.log("Working"); 
document.querySelector("#top-toolbar > colab-connect-button").shadowRoot.querySelector("#connect").click();
}
setInterval(ClickConnect,60000)

Above code would keep on clicking the page and prevent it from disconnecting.