【问题标题】:Replace Tab Name Chrome C#替换选项卡名称 Chrome C#
【发布时间】:2019-01-31 19:43:57
【问题描述】:

我想替换我的 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");
            }
        }
    }
}

但不能让它重命名选项卡。我试过更换它,但没有运气。有什么建议吗?

【问题讨论】:

    标签: c# google-chrome browser


    【解决方案1】:

    您需要将代码注入实际页面,以更改 <title> 标记的内容。

    这在 Chrome 本身之外是相当重要的。一种更简单的方法是创建Chrome extension for changing the page title,但这可能不是您想要的。

    【讨论】:

    • 我该怎么做?
    【解决方案2】:

    我建议按照@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");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-09
      • 1970-01-01
      • 1970-01-01
      • 2018-11-17
      • 1970-01-01
      • 2015-11-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多