我想替换我的chrome上的选项卡名称。我设法让它使用此代码检测选项卡
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");
}
}
}
}
但无法让它重命名标签。我试过更换它但没有运气。有什么建议?
我建议做@avigloz说的话! chrome的扩展并不难创建。看看How to start with chrome extensions
更简单的方法是制作Chrome扩展程序以更改页面标题,但这可能不是您要查找的内容。
如果您只想重命名该过程:
using System.Runtime.InteropServices;
[DllImport("user32.dll")]
static extern int SetWindowText(IntPtr hWnd, string text);
用法:
if (!chromeProcess.HasExited)
SetWindowText(chromeProcess.MainWindowHandle, "New title");
您需要将代码注入实际页面,以更改<title>
标记的内容。
从Chrome外部做起,这是非常重要的。一个更简单的方法是制作一个Chrome extension for changing the page title,但这可能不是你想要的。