/*
 * https://webfolder.io/license.html
 */
package io.webfolder.cdp.dom;

import java.io.IOException;
import java.util.List;

import io.webfolder.cdp.Example;
import io.webfolder.cdp.Launcher;
import io.webfolder.cdp.session.DocumentSnapshot;
import io.webfolder.cdp.session.Session;
import io.webfolder.cdp.session.SessionFactory;

@Example
public class CaptureDOMSnapshot {

    public static void main(String[] args) throws IOException {
        Launcher launcher = new Launcher();

        try (SessionFactory factory = launcher.launch();
                            Session session = factory.create()) {
            session.navigate("https://cnn.com");
            session.waitDocumentReady();
            // Returns a document snapshot, including the full DOM tree of the root node (including iframes,
            // template contents, and imported documents).
            List<DocumentSnapshot> snapshot = session.getDocumentSnapshot();
            for (DocumentSnapshot next : snapshot) {
                System.out.println(next.getContent());
                System.out.println("----------------------------------------");
            }
        } finally {
            launcher.kill();
        }
    }
}