Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to auto scroll a WebView after DOM changes in Cocoa / WebKit
    primarykey
    data
    text
    <p>I'm building a small Mac Application that gets continuously supplied with data via a web socket. After processing each data segment, the data is displayed in a <code>WebView</code>. New data <em>never replaces</em> any data in the <code>WebView</code> instead new data is always <em>appended</em> to the <code>WebView</code>'s content <em>using DOM manipulations</em>. The code sample below should give you an idea of what I'm doing.</p> <pre><code>DOMDocument *doc = self.webview.mainFrame.DOMDocument; DOMHTMLElement *container = (DOMHTMLElement *)[doc createElement:@"div"]; NSString *html = [NSString stringWithFormat:@"... omitted for the sake of brevity ... "]; [container setInnerHTML:html]; [doc.body appendChild:container]; </code></pre> <p>The rendering of the <code>WebView</code> apparently happens asynchronously. Is there a way to tell when the DOM manipulation finished and the content has been drawn? I want to use something like <code>[webview scrollToEndOfDocument:self]</code> to implement auto scrolling. Listening for DOM Events didn't help since they seem to be triggered when the DOM was modified but before these changes have been rendered. The code I'm using so far is similar to the following</p> <pre><code>[self.webview.mainFrame.DOMDocument addEventListener:@"DOMSubtreeModified" listener:self useCapture:NO]; </code></pre> <p>in conjunction with</p> <pre><code>- (void)handleEvent:(DOMEvent *)event { [self.webview scrollToEndOfDocument:self]; } </code></pre> <p>The problem with this code is that the scrolling happens too early. I'm basically always one data segment behind. Can I register for a callback / notification of any kind that is triggered when the content was drawn?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload