How to get the current URL from Chrome 28 from another Windows application?

前端 未结 2 1817
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-29 12:56

Up to Chrome V27 you could enumerate Chrome child window controls to get to the edit field and read the string value from there to get the current opened URL.

Unfort

相关标签:
2条回答
  • 2020-12-29 13:43

    AFAIK you could do this by creating a chrome extension which then communicates with the application using WebSockets.

    There's even a Delphi implementation of the Web Socket protocol(with examples) -> DelphiWs

    More relevant info here. That should get you started.

    0 讨论(0)
  • 2020-12-29 13:58

    Chrome supports the Windows accessibility APIs, so you can use those to extract information both from the chrome - including the broswer bar - and also from web pages. Think of this API as a more abstract version of enumerating window controls.

    Check out the Inspect Objects tool to explore what information you can get access to - it does look as though the address bar and contents are available.

    You can get the same information in C# using the AutomationElement set of classes:

    • use AutomationElement windowEl = AutomationElement.FromHandle(new IntPtr(hwnd)); as a starting point if you know the HWND of the tree
    • then try AutomationElement editEl = AutomationElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit)) to find the first element that has ControlType of Edit. FindFirst does a depth-first search of the tree, which looks like it will work in this case; can use the TreeWalker classes if you want to walk step-by-step yourself.
    • 'cast' the found element to a ValuePattern using: ValuePattern vp = (ValuePattern) editEl.GetCurrentPattern(ValuePattern.Pattern);
    • Finally, use string str = vp.Current.Value; to get the value of the edit.
    0 讨论(0)
提交回复
热议问题