In-browser code editors show up in a lot of products: a SQL workbench, a policy playground, a "try our language" widget, a low-code formula bar. Monaco and CodeMirror make that feel like VS Code in a tab.
The catch is that any grammar, completion, or lint rule the editor can apply without a server has to be in the page. This article is about what a client-side language package actually exposes, which checks should stay on a backend, and how to protect a proprietary analyzer without wrapping the editor shell.
The language package is a public module
A typical "smart" formula or policy editor looks like this:
import { StreamLanguage } from "@codemirror/language";
export const policyLang = StreamLanguage.define({
token(stream) {
return tokenize(stream, KEYWORDS, BUILTINS);
},
});
export function lintPolicy(text) {
const ast = parsePolicy(text, GRAMMAR);
return diagnose(ast, RULES); // your interesting part
}
After a production build, GRAMMAR, KEYWORDS, RULES, and diagnose live in a JS chunk the browser has to download, often next to a TextMate or Lezer grammar file on the same CDN. Monaco and CodeMirror are vendor libraries. A competitor who wants your product is after the language, the linter, and the completion tables, not the editor chrome.
A reader can:
- Pretty-print the chunk and copy
parsePolicyandRULESinto their own workbench. - Download a
.tmLanguage.jsonor Lezer grammar and reopen it in another editor. - Call
lintPolicyfrom the console with snippets the UI would have blocked. - Harvest "Pro" or staff-only rules that were only filtered from the diagnostics pane.
Minifying the bundle will rename diagnose. It will not hide a distinctive keyword, a magic lint threshold, or the shape of a grammar you spent months on.
Completions and "hidden" dialects still ship
Keep using a client editor. Syntax highlighting, undo, and a gutter are presentation. Shipping a public language server protocol over a web socket is also fine when the official analyze call goes to your server.
Do not put the authoritative type checker, a paid dialect, or an unpublished lint pack only in the widget and call the review done. A plan check that unhides "advanced diagnostics" is a UI branch. If rules-pro.js is already on the CDN, a visitor does not need to pass your if.
Tree-sitter or WASM grammars are harder to read than pretty-printed JavaScript. They are still files a determined reader can save and reuse. The completion list next to them is usually not compiled at all.
What to leave on the server
Some checks should run — or at least be confirmed — on the server:
- Diagnostics that enforce a license, a quota, or a paid dialect.
- Unpublished language features, partner-only builtins, and staff rules that would reveal a rollout you have not announced.
- Any analysis that needs data the browser should not have (other tenants' schemas, production catalogs, secret feature flags).
- Tokens for a cloud language-server that you were tempted to drop into the editor options.
The browser can still highlight tokens, show a local preview, and send the buffer for an official result. The result you stamp as "passed" can come from an API that already knows the account and the entitlement.
What to protect in the client
You may still need a slice of logic on the device: an offline parser for a field tool, a compact lint that must feel instant on every keystroke, or a custom completion scorer you do not want copied wholesale. For that slice:
- Keep official "passed" results, paid dialects, and unpublished builtins on the server.
- Minify the app as usual; leave Monaco or CodeMirror alone.
- Extract
diagnoseorparsePolicyand apply a real protection pass — identifier renaming and string tables as a floor, VM-style protection if wholesale reuse of the analyzer is the risk you care about. Measure keystroke latency before you protect a linter that already has a tight budget. - Keep production source maps and unused rule packs off the public CDN.
A JS VM obfuscator compiles that function to a custom bytecode and ships a small interpreter. Pretty-printing the chunk no longer reconstructs the original diagnose; you get bytecode and a dispatcher. That is slower than a bare walk of the AST, which is why you protect the analyzer, not the editor shell, and why protection is not a substitute for an official server-side check.
VEILVM is a browser-based JSVMP workspace you can point at one extracted function before you wire protection into CI. Protection raises the cost of casual inspection and wholesale reuse. It does not make a public grammar file a secret, and it does not replace a server-side official lint for anything you will certify.
Checklist
- [ ] Official or billed diagnostics are computed or re-checked on the server after entitlements.
- [ ] Paid and unreleased rule packs are not sitting in the public asset directory.
- [ ] The editor library is left alone; only your parser or linter is a candidate for protection, and only if the keystroke path can afford it.
- [ ] Plan checks that "unlock" a dialect are treated as UI, not as access control for the grammar file.
- [ ] Production source maps are not downloadable from the CDN.
- [ ] End-to-end tests lint a fixture buffer against the minified (and, if applicable, protected) production editor and the real API.
If you want to try VM protection on a single extracted function, VEILVM runs in the browser with no sign-up: 3 free runs a day, up to 5 KB per file (resets at 00:00 UTC). A free account raises the input limit to 30 KB. Pro is $9/month or $79/year and adds an API so the protection step can run in CI. Standard requests are processed in memory and are not written to logs. Start at https://vm.ldvmp.com.
Top comments (0)