How does metamask knows it need to popup to show the contract interaction?

Whenever I click on MetaMask, a popup comes up on the frontend. I am curious to know what event triggers that.

Hello @Ashu101 ! Welcome to MetaMask community !

Do you mean the MetaMask icon on the browser extension bar?