0

i want to replace the tab name on my chrome. i have managed to get it detect the tab using this code

public void FetchProcess()
{
    Process[] processes = Process.GetProcessesByName("chrome");

    if (processes.Length > 0)
    {
        foreach (Process item in processes)
        {
            int milliseconds = 100;
            Thread.Sleep(milliseconds);
            if (item.MainWindowTitle.Contains("YouTube - Google Chrome"))
            {
                MessageBox.Show("Yayy");
            }
        }
    }
}

But cannot get it to rename the tab. I have tried replacing it but no luck. Any suggestions?

Dan Flanagan
  • 504
  • 2
  • 13

2 Answers2

1

I would recommend to do what @avigloz said! An extension for chrome is not that hard to create. Check this out How to start with chrome extensions

An easier way would be to make a Chrome extension for changing the page title, but that may not be what you're looking for.

If you just want to rename the process:

using System.Runtime.InteropServices;

[DllImport("user32.dll")]
static extern int SetWindowText(IntPtr hWnd, string text);

Usage:

if (!chromeProcess.HasExited)
    SetWindowText(chromeProcess.MainWindowHandle, "New title");
0

You'd need to inject code into the actual page, to change the contents of the <title> tag.

This is fairly non-trivial to do from outside Chrome itself. An easier way would be to make a Chrome extension for changing the page title, but that may not be what you're looking for.

avigloz
  • 46
  • 7