Skip to content

software-mansion/popcorn

Repository files navigation

License

Popcorn

Popcorn is a library that allows you to run client-side Elixir in browsers, with Javascript interoperability

Popcorn is early stages and may break. Please report an issue if it does. Contributions are very welcome, but please open an issue before commiting too much effort.

Under the hood, Popcorn runs AtomVM, a tiny Erlang VM.

Examples

The examples are hosted at popcorn.swmansion.com, and the source code is in the examples directory.

Getting started

Note: Popcorn currently only works OTP 26.0.2 and Elixir 1.17.3. We're working to lift this requirement.

Popcorn requires just a few short steps to setup. Firstly, add the project to dependencies:

# mix.exs

def deps do
  {:popcorn, github: "software-mansion/popcorn"}
end

Create a startup module:

# lib/my_app/start.ex

defmodule MyApp.Start do
  def start() do
    Popcorn.Wasm.register("main")
    IO.puts("Hello from WASM")
  end
end

and register it in the config, along with the directory to output static artifacts:

# config/config.exs
import Config
config :popcorn, start_module: MyApp.Start, out_dir: "static/wasm"

Run mix deps.get and mix popcorn.cook. The latter will generate WASM artifacts in the static/wasm directory. Add a simple HTML file that will load it:

<!-- index.html -->
<html>
  <script type="module">
      import { Popcorn } from "./wasm/popcorn.js";
      await Popcorn.init({ onStdout: console.log });
  </script>
  <body></body>
</html>

The easiest way to host the page is to generate a simple HTTP server script with mix popcorn.simple_server and run it with elixir server.exs. Then, at http://localhost:4000, you should see Hello from WASM printed in the console.

The webpage can also be hosted with any HTTP static file server, but it must add the following HTTP headers:

Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp

Otherwise, browsers refuse to run WASM.

Authors

Popcorn is created by Software Mansion.

Since 2012 Software Mansion is a software agency with experience in building web and mobile apps as well as complex multimedia solutions. We are Core React Native Contributors and experts in live streaming and broadcasting technologies. We can help you build your next dream product – Hire us.

Copyright 2025, Software Mansion

Software Mansion

Licensed under the Apache License, Version 2.0

About

Running Elixir in the browser

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors 7