Check out example codes for "how to stop google colab from disconnecting". It will help you in understanding the concepts better.

Code Example 1

function ConnectButton(){
    console.log("Connect pushed"); 
    document.querySelector("#top-toolbar > colab-connect-button").shadowRoot.querySelector("#connect").click() 
}
setInterval(ConnectButton,60000);

Code Example 2

function ClickConnect(){
    console.log("Clicked on connect button"); 
    document.querySelector("colab-connect-button").click()
}
setInterval(ClickConnect,60000)

Learn ReactJs, React Native from akashmittal.com