Tag: Web AI

  • Running and Testing AI-Generated Web Apps in the Browser

    Running and Testing AI-Generated Web Apps in the Browser

    AI tools have become really good at generating entire web apps from a single prompt. But how do you know whether AI-generated web apps actually work? You have to install the dependencies, start the dev server, open the app in a browser and click around. For this, app builders typically spin up a container per app, which can add some overhead. So I wondered: what if all of this could happen right in the browser instead?

    That is why I built Sandburg. The name is German for sand castle, which felt fitting for what is basically a very elaborate sandbox. Sandburg starts a web project with its own dev server on a Node.js runtime that runs in a browser tab, and checks it end to end with Playwright in that very same tab. No containers or VMs needed. The browser itself is the container and runs many sandboxes side by side.

    You can see it in action on the demo site.

    The Sandburg demo site with five demos: a Next.js 16 habit tracker, a Vite + React counter, a Vue + Express + SQLite notes app, a SvelteKit app and an Angular 22 task board, each starting the project's own dev server in the browser tab
    The Sandburg demo site: Next.js, Vite + React, Vue + Express + SQLite, SvelteKit and Angular, each on its own dev server inside the browser tab.

    Why run apps in the browser?

    Coming from the WordPress world, I have seen first-hand how much WordPress Playground changed things by running WordPress entirely in the browser. That was a big inspiration: could the same idea work for modern JavaScript stacks, and be reliable enough to tell you whether an app works? Running in the browser has some nice advantages:

    1. Cost
      No container or VM per app. A single browser runs many sandboxes in parallel.
    2. Isolation
      The browser is one of the most battle-tested sandboxes out there. Each app gets its own origin, Chromium runs inside its OS sandbox, and the network is only reachable through a per-sandbox allowlist.
    3. No backend needed
      A run can work with nothing but static files, so it can even be hosted on GitHub Pages.

    The real tools, not a reimplementation

    I first tried existing in-browser runtimes like Nodebox and almostnode, but they reimplement or emulate the tools rather than running them. almostnode’s “Vite”, for example, doesn’t read vite.config.*, doesn’t run plugins, and pins React 18 no matter what package.json says. If the sandbox isn’t running the same thing you’d run locally, its verdict doesn’t mean much.

    Sandburg has a runtime of its own: Node.js 24 in a Web Worker, with a virtual file system, a module loader and Node’s built-in modules. It runs a project’s dev script as written, be it next dev, concurrently "vite", or ng serve. Backend parts such as Express and SQLite are also supported. Native tools such as SWC, esbuild or Tailwind’s oxide run on their WebAssembly builds, and child processes are simply more runtimes.

    Testing apps end to end with Playwright

    Running an app is only half of the story. Every run has built-in checks, so a server error or an uncaught error fails it. On top of that, a checks file exports named checks that get the app’s frame, Playwright’s expect, and an appUrl() helper:

    import type { Checks } from 'sandburg';
    
    export default {
      'counter increments on click': async ({ app, expect }) => {
        await app.getByRole('button', { name: /count is/ }).click();
        await expect(app.getByRole('button', { name: /count is/ })).toHaveText('count is 1');
      },
      'about page': async ({ app, expect, appUrl }) => {
        await app.goto(appUrl('/about'));
        await expect(app.getByRole('heading', { level: 1 })).toHaveText('About');
      },
    } satisfies Checks;Code language: JavaScript (javascript)

    Sandburg is available on npm and requires Node.js 24 or later:

    npm install --save-dev sandburg
    npx sandburg run ./my-app --checks checks.spec.ts

    There is also a batch command, a library API, and a GitHub Action for CI. Every failure gets a class, like app-bug or timeout, and app bugs point at the file and line where the dev server reported them. That’s exactly what you want to feed back to an LLM so it can fix its own mistakes. And for checks written by a coding agent, --checks-in page runs them in the sandbox tab instead of on your machine.

    Generate an app right in your browser

    Since the npm registry answers cross-origin requests, the Sandburg demo page can also install packages and compile modules by itself. Then a run needs nothing but static files. That unlocked the part I’m most excited about: the app generator (à la WebDev Arena). Describe an app, and Claude or Gemini (with your own API key) writes it with the framework of your choice, complete with a backend and a SQLite database. Your browser tab installs it from npm and runs it. Follow-up requests change the running app, and errors are sent back to the model to fix.

    The Sandburg app generator page: example prompts, a provider and model picker with an API key field that stays in a sandboxed frame, a framework selector, and an empty preview with steps for writing code, mounting, npm install, starting the dev server and rendering
    The app generator: pick a model and a framework, describe an app, and it installs and runs in the same tab.

    Note: The generated app runs on the same origin as the page, so it could in theory read anything stored there. To prevent access to your API keys, it uses sandboxed iframes and nothing is stored anywhere.

    For the sake of it, I even put together a small app-generation eval setup across various models, stacks and tasks. There is also a Harbor environment that lets coding agents build and test apps without Docker.

    Try it out

    Sandburg is still a young project. Native addons without a WebAssembly build won’t work, and neither will programs other than Node, such as git or python. But the list of what does work is already much longer than I expected.

    Check out the GitHub repository for the user guides and the architecture decision records, install the npm package, give the generator a try, and let me know what you think! Bug reports, feature requests, and pull requests are all very welcome.

  • Web AI for WordPress

    The web platform team in Chrome is working on built-in AI features, where the browser provides AI models, including large language models (LLMs), to enable on-device AI for browser features and web platform APIs. This is a game changer and a huge opportunity for WordPress to democratize AI-assisted publishing. Let me tell you why.

    If WordPress does not want to fall behind its competitors, it must seamlessly provide typical AI features users nowadays expect from a publishing platform. There are already various AI WordPress plugins, but they all come at a cost—both literally and metaphorically. These plugins all rely on third-party server-side solutions, which impacts both your privacy and your wallet.

    Web AI has several key benefits over a server-side approach. It brings models to the browser, protecting sensitive data and improving latency.

    Web AI is the overarching term for the ability to run AI solutions in the browser using JavaScript, WebAssembly, and WebGPU. This space was pioneered by libraries such as TensorFlow.js and Transformers.js. Using those tools, websites can download models and run tasks of their choice directly in the browser.

    Chrome’s built-in API

    If everyone has to download and update these models all the time, this doesn’t really scale and isn’t really sustainable. That’s where Chrome’s built-in AI steps in. It is just one form of client-side AI or Web AI.

    With the built-in AI, your site or web app will be able to run various AI tasks against foundation and expert models without having to worry about deploying and managing said models. Chrome achieves this by making Gemini Nano available through dedicated web platform APIs, running locally on most modern computers.

    Note: This functionality is currently only available in Chrome Canary. Join the early preview program to learn how to access those early-stage built-in AI features and provide feedback.

    At the moment, the Chrome team expects the built-in AI to be beneficial for both content creation and content consumption. During creation, this could include use cases such as writing assistance, proofreading, or rephrasing. On the consumption side, typical examples are summarization, translation, categorization, or answering questions about some content.

    Early preview program participants will receive more detailed information about the following APIs:

    To give you an example, using the prompt API is pretty straightforward:

    const session = await ai.languageModel.create({
      systemPrompt: "You are a friendly, helpful assistant specialized in clothing choices."
    });
    
    const result = await session.prompt(`
      What should I wear today? It's sunny and I'm unsure between a t-shirt and a polo.
    `);
    
    console.log(result);
    
    const result2 = await session.prompt(`
      That sounds great, but oh no, it's actually going to rain! New advice??
    `);Code language: JavaScript (javascript)

    The other APIs are similarly straightforward to use. By the way, if you are an avid TypeScript user, there are already type definitions which I helped write.

    Eager to build something with this new API? The Google Chrome Built-in AI Challenge challenge invites developers to explore new ground by creating solutions that leverage Chrome’s built-in AI APIs and models, including Gemini Nano. Cash prizes totaling $65,000 will be awarded to winners.

    Web AI Advantages

    • The browser takes care of model distribution and updates for you, significantly reducing the complexity and overhead.
    • Everything is processed locally on-device, without sending your sensitive data elsewhere, keeping it safe and private.
    • No server round trips means you can get near-instant results.
    • You can access AI features even if you’re offline or have bad connectivity.
    • Save money by not having to use expensive third-party services or sending large models over a network.

    This is not the first time where doing things client-side is better than on the server.1 You could of course consider a hybrid approach where you handle most use cases on-device and then leverage a server-side implementation for the more complex use cases.

    Using built-in AI in WordPress

    If WordPress core wants to offer AI capabilities to each and everyone of its users, it can’t jeopardize user’s privacy by relying on expensive third-party services. The project also does not have the resources or infrastructure to maintain its own API and running AI inference on a shared hosting provider in PHP is also not really something that works.

    That’s why Web AI and particularly Chrome’s built-in AI are a perfect match for WordPress. With it, users benefit from a powerful Gemini Nano model that helps them accomplish everyday tasks.

    The modern and extensible architecture of the WordPress post editor (Gutenberg) makes it a breeze to leverage Chrome’s built-in AI. To demonstrate this, I actually built several AI experiments. They enhance the user experience and accessibility for both editors and readers.

    Here’s an overview:

    Provide tl;dr to visitors

    Screenshot of a "Summarize post content" button on a blog post, powered by Web AI.
    Web AI makes it easy to summarize content with the click of a button — all done on-device.

    Uses Chrome’s built-in summarization API to provide readers a short summary of the post content. The UI is powered by WordPress’ new Interactivity API.

    Writing meta descriptions based on the content

    Using the dedicated summarizer API, the content can be easily summarized in only a few sentences.

    “Help me write”

    Block toolbar in the WordPress editor with "Help me write" features, using Web AI to do things like rephrasing or shortening text.
    AI-powered “Help me write” quickly became an essential feature for many users.

    Options for rewriting individual paragraphs à la Google Doc, like rephrasing, shortening or elaborating.

    Generate image captions / alternative text

    Uses Transformers.js and Florence-2 to generate image captions and alternative text for images directly in the editor. Also integrated into Media Experiments, which supports video captioning too.

    Generate a memorable quote

    A slight variation on the summarization use case, this extracts a memorable quote from the article and gives it some visual emphasis.

    Assigning tags & categories to blog posts

    Suggest matching tags/categories based on the content, grabs a list of existing terms from the site and passes it to the prompt together with the post content.

    Sentiment analysis for content / comments

    Using a simple prompt to say whether the text is positive or negative. Could be used to suggest rephrasing the text à la Grammarly, or identify negative comments.

    Summary

    From summarizing content to more complex examples like automatically categorizing posts, the currently explored use cases peek at what’s possible with Web AI in WordPress. Their main advantage lies in their combined strength and the deep integration into WordPress, making for a seamless UX. Chrome’s built-in AI also makes this functionality ubiquitous, as every WordPress user could leverage it without any browser extension, plugin, or API. This is just the beginning. In the future, more complex AI features could push the boundaries of interacting with WordPress even further.

    1. I’m of course talking about client-side media processing. ↩︎