Activate Tab on Chrome

Copper Contributor

After launch a URL on a single tab of Chrome, the following will work just fine. But It will not work if Google.com is on an inactive tab of multiple tabs. Is there other way to do that? Thanks.

 

Start-Process chrome ("https://www.google.com")
Start-Sleep -Seconds 3

$p = Get-Process Chrome | ? { $_.MainWindowTitle.Contains('Google') }

[Microsoft.VisualBasic.Interaction]::AppActivate($p.Id)

 

PS 5 on Windows 10

2 Replies

Hi @Yuansheng Zhang 

bases on what I see, all Google Chrome Tabs are Child-Process to Google Chrome it self

Check this

image.png

even with the code you provide, if you have multiple Chrome Tabl open, it will only get the Main process

The result from your Code.

farismalaeb_0-1609876701956.png

Did you notice the same Process ID?

Google is changing the Main Windows Title based on the Active Tab, this is why you are facing this issue, 

I tried to dig via Process Explorer and see if I can get anything via the command ID or whatever parameter assigned to the tab but did not find anything.

it seems that other tabs don't hold a Title until activation, Check this

(Get-Process Chrome).foreach{$_.MainWindowTitle}

the only result you will get is the active Window Title, and a lot of other null values

 

 

Small hint that might help, Check SysInternal TCPView, get the output from the console, you will get all the destination that chrome is connecting to, yet the process maybe a bit slow, but it can work as a workaround.