======= Android ======= The primary function :func:`parseDocument` can be called on multiple elements and multiple times per session. The application will continuously and progressively build the layout files into a single entity with combined shared resources. .. warning:: Calling :func:`saveAs` or :func:`copyTo` methods before the images or fonts have completely loaded can cause them to be excluded from the generated layout. In these cases you should use the asynchronous :func:`parseDocument` and not :func:`parseDocumentSync`. Example usage ============= .. code-block:: html .. code-block:: :caption: Cross-origin support squared.prefetch("css").then(() => squared.parseDocument()); // Chromium /* OR */ Promise.all( squared.prefetch("css", true), // All stylesheets squared.prefetch("css", "./undetected.css", element.shadowRoot), squared.prefetch("svg", "http://embedded.example.com/icon.svg", "../images/android.svg") ) .then(() => squared.parseDocument()); .. code-block:: :caption: Kill request squared.kill("30s").then(pid => { // Abort next request in 30 seconds if (pid > 0) { /* KILLED */ } }); /* OR */ await squared.saveAs("project.zip", { timeout: 10 }); // Cancels request if not complete in 10 seconds .. code-block:: :caption: Modify attributes squared.parseDocument().then(() => { const body = squared.findDocumentNode(document.body); body.android("layout_width", "match_parent"); body.lockAttr("android", "layout_width"); }); .. code-block:: :caption: Observe element attributes await squared.parseDocument({ element: document.body, observe(mutations, observer, settings) { squared.reset(); // Required after a File action squared.parseDocument(settings).then(() => { squared.copyTo("/path/project", { modified: true }).then(response => { console.log(response); }); }); } }); squared.observe(); .. code-block:: :caption: Observe element source files await squared.observeSrc( "link[rel=stylesheet]", (ev, element) => { squared.reset(); squared.parseDocument().then(() => squared.copyTo("/path/project")); }, { // squared.json port: 8080, secure: false, action: "reload", expires: "1h" } );