I'm in the process of replacing a .NET's WebBrowser
for a WebKit.NET
, and one of the functionalities I've been using in the WebBrowser
that I can't figure out how to implement in the wrapper I'm writing around WebKit
is the ability to pass DOM elements from and to JavaScript and C# code.
In a WebBrowser
you'd just call InvokeScript
and pass an the DomElement
property of an HtmlElement
as a parameter, and the JavaScript function would get the element. Same way, you can pass an element from JavaScript to C# and the C# code would get a DomElement
object.
In WebKit
as far as I know I cannot do this. The InvokeStriptMethod
method is broken, but the StringByEvaluatingJavaScriptFromString
is not, which let me inject scripts into the current document and invoke them any time later.
Note that these documents won't be my own created documents so I can't do stuff like assigning ID's to every element. This is a web scraper and I need to avoid messing with the document's elements as much as possible.
One hack that would probably work is assigning a temporary ID to the element and keeping the old ID backed up, then I can do a GetElementById
call from either JavaScript or C# to get the element, and then reassign the old element's ID. The problem is that WebKit's GetAttribute('id')
will give me an empty string when the ID is undefined
, so there is no way for my C# code to know whether the ID was an empty string or undefined
, and who knows, the current web page's script could rely on the ID being undefined
for some reason, so setting the ID to an empty string could mess up their javascript.
Anyone has a better idea or is there any other WebKit
method I could use?