获取 Chrome .Net 中打开的标签页的 URL

Get the URLs of opened tabs in Chrome .Net

你好 可以帮助解决这个问题

我尝试获取所有 chrome 选项卡的 Url 并将它们插入列表框

,项目已经 运行 没有任何错误。

代码形式 1:

Imports System.Runtime.InteropServices
Imports NDde.Client

Public Class Form1

<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
Private Shared Function FindWindow(
ByVal lpClassName As String,
ByVal lpWindowName As String) As IntPtr
End Function

<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
Private Shared Function FindWindowEx(ByVal parentHandle As IntPtr,
              ByVal childAfter As IntPtr,
              ByVal lclassName As String,
              ByVal windowTitle As String) As IntPtr
End Function

<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
End Function

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim h As IntPtr
    For Each p As Process In Process.GetProcessesByName("chrome")
        h = FindWindow("Chrome_WidgetWin_1", p.MainWindowTitle)
        Exit For
    Next
    Dim urlH As IntPtr
    urlH = FindWindowEx(h, 0, "Chrome_OmniboxView", Nothing)
    Dim urlHH As IntPtr = Marshal.AllocHGlobal(100)
    Dim NumText As Integer = SendMessage(urlH, &HD, 50, urlHH)
    Dim url As String = Marshal.PtrToStringUni(urlHH)
    ListBox1.Items.Add(url)
End Sub
End Class

错误:Error Issue

你可以找到更简单的东西(在你的项目资源中使用 Autohotkey.exe)

  • 您可以使用 ahk 获取当前活动的选项卡 url,此外还可以复制 url 功能
  • 设置计时器以粘贴从剪贴板复制的内容。

我认为你可以做到。很难兼容 System.Windows.Automation