4

I need to get html after all javascripts run.I use WebKit.NET for it and the problem is that WebKitBrowser.StringByEvaluatingJavaScriptFromString doesn't return anything even with simple alert().And when I pass "document.getElementsByTagName('html')[0].outerHTML" (it is actually what I need to get) as the argument it throws the System.AccessViolationException(Attempted to read or write protected memory). And of course I do call StringByEvaluatingJavaScriptFromString in the function that is stick to the DocumentCompleted delegate.I've tried to do the same with WebView in objective-c with the same function StringByEvaluatingJavaScriptFromString and with the same argument "document.getElementsByTagName('html')[0].outerHTML" and it works good as well as it works good with "document.getElementsByTagName('html')[0].outerHTML" in console of the browser. Please help or maybe give alternatives how can I get whole html after runnig all javascripts.

public Form1()
    {
        InitializeComponent();          
        webKitBrowser1.Navigate("http://famous-design.ru/stoly/");

        webKitBrowser1.DocumentCompleted += webKitBrowser1_DocumentCompleted;

    }


    void webKitBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {

        string str = webKitBrowser1.StringByEvaluatingJavaScriptFromString("document.getElementsByTagName('html')[0].outerHTML");

    }    
1
  • why use: document.getElementsByTagName("html")[0] when you could use: document.documentElement Commented Jan 19, 2022 at 12:31

2 Answers 2

1

What i do is i integrate webKitBrowser1.StringByEvaluatingJavaScriptFromString with webKitBrowser1.Document.InvokeScriptMethod :

So you have this:

webKitBrowser1.StringByEvaluatingJavaScriptFromString("function GetElement() {document.getElementsByTagName('html')[0].outerHTML};")
var returnvalue = (string) webKitBrowser1.Document.InvokeScriptMethod("GetElement");

where the return value is returnvalue in the code with the object string (Of course you can change it)

Sign up to request clarification or add additional context in comments.

Comments

0

I got that error too, I tried changing html to body like this:

document.getElementsByTagName('body')[0].outerHTML

Then it worked.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.