03 / open source / 01 of 02
CodeArena, a coding-practice platform that runs in the browser
A LeetCode-style practice site that runs in the browser, with 20 problems, a Monaco editor and runners for JavaScript, Python and C++. It has no backend of its own: JavaScript and Python run in the page, and C++ goes to the public Judge0 API.
What it does
You pick a problem, write a solution and press Ctrl+Enter. Each test case comes back as pass, fail, error or time limit exceeded as it finishes. Code and solved problems are saved in localStorage, so progress survives a reload without an account. Every problem has an editorial.

Problems are folders
Each problem is a folder with two files: problem.js for the statement, starter code and function name, and testcases.js for inputs, expected output and how to compare them. A registry finds every folder at build time with Vite's import.meta.glob, so adding a problem means adding a folder.
The glob is eager, so every problem ships in the main bundle. At 20 problems and 106 test cases that is fine. At a few hundred it would not be.
Running JavaScript without freezing the tab
The interesting problem is code that never returns. A while (true) on the main thread freezes the tab, and nothing on that thread can interrupt it. So each test case gets its own Web Worker, created from a Blob URL. Inside it, the user's code is wrapped with the Function constructor and the named function is called with the test input.
The timer lives on the main thread. If the worker has not answered within the limit, 3 seconds by default, the main thread calls worker.terminate() and records Time Limit Exceeded. Terminating a worker kills its thread, and in a browser that is the only dependable way to stop a synchronous loop.
Test cases run one after another. A fresh worker per case costs some start-up time, and in return no state leaks between cases and each result shows as soon as it lands. For in-place problems like Rotate Image, the test checks the mutated argument instead of the return value.
More than one right answer
Some problems accept several answers, so each test case names one of five comparators: exact, deep structural equality, unordered arrays (Two Sum indices in either order), unordered groups (Group Anagrams), and a palindrome check for Longest Palindromic Substring, where any palindrome of the right length passes.
Python and C++, and where they fall short
Python runs through Pyodide, loaded from a CDN, on the main thread. Each run gets a fresh namespace, and if the code defines a Solution class the runner creates one and calls the method on it. There is no time limit. A Python infinite loop freezes the tab, which is exactly the failure the JavaScript runner was built to prevent.

C++ goes to the public Judge0 instance. For each test case the runner generates a main() that declares the inputs with types guessed from the JSON values, calls the method on Solution and prints the result as JSON for the same comparators. Every test case is a separate compile-and-run request to a third-party service, and the per-problem time limit is not sent, so C++ gets whatever limit the public instance applies.
Coverage is uneven. Only 5 of the 20 problems ship Python and C++ starter code. On the other 15 the editor opens empty when you switch language.
Screenshots


What broke
- Reading the C++ wrapper again for this write-up, I found that an array of single characters is declared as vector<char> but its elements are written in double quotes, as strings. That does not compile, so Reverse String in C++ should fail with a compilation error whatever the user writes. String inputs are not escaped either.
- The README and page metadata still describe a JavaScript-only site, written before Python and C++ were added.
What I would change
- Move Pyodide into a worker and reuse the terminate-on-timeout pattern, so Python gets a real time limit.
- Put C++ behind a small proxy or a self-hosted Judge0, send the per-problem time limit, and compile once per run instead of once per test case.
- Finish Python and C++ starter code for the other 15 problems, fix character arrays and escape string literals in the C++ wrapper, and make the problem glob lazy before the list grows.
Questions
- Does C++ run in the browser?
- No. It is compiled and run by the public Judge0 API. JavaScript and Python run in the browser.
- Can a Python infinite loop hang the page?
- Yes, today it can. Only the JavaScript runner enforces a time limit.