A browser with Wasm GC and tail call support is required for this demo. We recommend using either Mozilla Firefox or Google Chrome.
Wikipedia viewer
Here we have three pages: one that sources a wikipedia page, and two that can point to a hyperlink and follow it. I have added a text box at the top where the topic can be switched. This demo was inspired by this video.
Topic:
The most interesting new feature here is that we have an async fetch of a webpage triggered by page rules. When a page declares that some web content needs to be accessed, how do we handle waiting for that to be fetched? We probably want to avoid everything becomes unresponsive or update cycles to overlap. Since we don't have access to async/await in Scheme (though perhaps we do, see Hoot docs), I decided to handle this in Javascript.
The getUrl function is registered to be accessible by Scheme. It attempts to get the contents from a cache and kicks of an async function to retrieve it through the fetch API if the cache does not contain it. Crucially, the resulting promise is not awaited. At some later point, after the promise is resolved, the cache may now contain the content we were looking for. In order to notify RealTalk that content has arrived, we can simply dispatch an event and have that trigger another update cycle:
Pointing at links requires only a small modification to our previous code for whiskers. The main logic is in declaring a page to be a 'wiki': for ease of coding we will include a page's dimensions in that one fact. Pages that are wikis retrieve a wikipedia page on the topic and project the first paragraph to their right. All <a> elements within that paragraph have their geometry asserted.
Page #1 is always declared as a wiki; the other pages are wikis when they point at a link, and their topic is the link's inner HTML text: