I'm looking to incorporate some Javascript scripts into IE and then trigger certain methods.
Here is the C# code I attempted using (the Javascript code builds xpath from a known HTML element).
string xpath = @"
(function(win) {
""use strict"";
var doc = win.document;
if (doc._xpath_installed) return;
doc._xpath_installed = true;
// Rest of the JavaScript code here...
})(window);
";
After that, I proceed to inject the xpath string and call a method,
// Code snippet for injecting xpath and invoking a method
// Executing script in JScript
doc.parentWindow.execScript(xpath, "JScript");
object[] args = new object[2];
args[0] = element;
args[1] = 1;
object result = doc.GetType().InvokeMember("createXPath", BindingFlags.Instance | BindingFlags.InvokeMethod, null, doc, args);
This setup functions properly in Internet Explorer 11 on Windows 10.
However, when the website is added to Compatibility View (settings-> compatibility view settings), the InvokeMember call throws an exception "Exception from HRESULT: 0x80020101". This error suggests that there might be script errors within the Javascript code.
In this scenario, my question is - Is there a way to debug this Javascript code effectively without facing difficulties caused by the error code 0x80020101?