{"id":13961764,"url":"https://github.com/worker-tools/html-rewriter","last_synced_at":"2026-03-16T08:30:16.183Z","repository":{"id":57673439,"uuid":"480869545","full_name":"worker-tools/html-rewriter","owner":"worker-tools","description":"WASM-based implementation of Cloudflare's HTML Rewriter for use in Deno, browsers, etc.","archived":false,"fork":false,"pushed_at":"2024-04-28T13:11:11.000Z","size":4281,"stargazers_count":78,"open_issues_count":3,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-06T00:26:02.147Z","etag":null,"topics":["cloudflare-workers","deno","html","html-rewriter","polyfill","streaming","wasm","webassembly","worker"],"latest_commit_sha":null,"homepage":"https://workers.tools/html-rewriter","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/worker-tools.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-04-12T15:32:42.000Z","updated_at":"2024-10-04T19:36:43.000Z","dependencies_parsed_at":"2022-08-31T11:51:07.895Z","dependency_job_id":null,"html_url":"https://github.com/worker-tools/html-rewriter","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/worker-tools%2Fhtml-rewriter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/worker-tools%2Fhtml-rewriter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/worker-tools%2Fhtml-rewriter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/worker-tools%2Fhtml-rewriter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/worker-tools","download_url":"https://codeload.github.com/worker-tools/html-rewriter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219848897,"owners_count":16556331,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudflare-workers","deno","html","html-rewriter","polyfill","streaming","wasm","webassembly","worker"],"created_at":"2024-08-08T17:01:25.431Z","updated_at":"2026-03-16T08:30:16.127Z","avatar_url":"https://github.com/worker-tools.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# HTML Rewriter\n\nWASM-based implementation of Cloudflare's HTML Rewriter for use in Deno, browsers, etc. \n\nIt uses `lol-html` under the hood, the same implementation used by Cloudflare Workers. It is based on [Miniflare's WASM build](https://github.com/mrbbot/html-rewriter-wasm).\n\n## Installation\nThis package includes 2 versions of HTML Rewriter. \n\n`index.ts` loads the WASM that is co-located with this module via fetch and (streaming-) instantiates the module that way. In Deno, this works via file system (if you've downloaded the module) and web (when loading from deno.land/x or even githubusercontent.com). \nHowever, if you are using this version with other tooling, depending on the bundler and configuration the WASM source may or may not be included...\n\n`base64.ts` has the required WASM inlined as compressed base64. The total size is 447K (345K gzipped). \nThis ensures that HTML Rewriter is working properly when bundled, offline, etc. \nThe \"hackyness\" of ~400K of inlined WASM and relying on [`DecompressionStream`][dcs] is significant (without compression, the file size would be 1.2MB), but its simplicity makes it easier to get it to work with various bundlers (including Deno's own, as of this writing).\n\n[dcs]: https://developer.mozilla.org/en-US/docs/Web/API/DecompressionStream\n\n### Use in Browser\nFor use in the browser it's best to install the \"node-ified\" package from npm and use it with a bundler.\n\n```sh\nnpm install @worker-tools/html-rewriter\n```\n\nWhich version of HTML Rewriter to pick depends on which bundler you are using:\n\nFor **Webpack 4**, it's best to use the non-ESM base64 version via its full path: `@worker-tools/html-rewriter/script/base64`. \n\n**Webpack 5** treats the regular version correctly by default, which can be imported as `@worker-tools/html-rewriter`. \n\nFor **esbuild** it's best to use the base64-version via `@worker-tools/html-rewriter/base64`. \n\nYou can explore the full contents of the npm package [here](https://unpkg.com/browse/@worker-tools/html-rewriter/).\n\n## Usage\n\n```ts\nimport { \n  HTMLRewriter \n} from 'https://ghuc.cc/worker-tools/html-rewriter/index.ts'\n\nnew HTMLRewriter()\n  .on(\"p\", {\n    element(element) { \n      element.tagName = \"h1\" \n    },\n  })\n  .transform(new Response('\u003cp class=\"red\"\u003etest\u003c/p\u003e'))\n  .text().then(x =\u003e console.log(x))\n```\n\nFor more on how to use HTMLRewriter, see the [Cloudflare Workers Docs](https://developers.cloudflare.com/workers/runtime-apis/html-rewriter/).\n\n\n## Building\n\nMake sure you've initialized all git submodules. It is 2 levels deep.\n\n```sh\ngit submodule update --init --recursive\n```\n\nMake sure you have `rustup` installed. Then run\n\n```sh\nmake dist\n```\n\nThis will build a custom version of `wasm-pack` first, then use it to compile `lol-html` to WASM. Please see the submodules for details on why this is necessary.\n\n--------\n\n\u003cp align=\"center\"\u003e\u003ca href=\"https://workers.tools\"\u003e\u003cimg src=\"https://workers.tools/assets/img/logo.svg\" width=\"100\" height=\"100\" /\u003e\u003c/a\u003e\n\u003cp align=\"center\"\u003eThis module is part of the Worker Tools collection\u003cbr/\u003e⁕\n\n[Worker Tools](https://workers.tools) are a collection of TypeScript libraries for writing web servers in [Worker Runtimes](https://workers.js.org) such as Cloudflare Workers, Deno Deploy and Service Workers in the browser. \n\nIf you liked this module, you might also like:\n\n- 🧭 [__Worker Router__][router] --- Complete routing solution that works across CF Workers, Deno and Service Workers\n- 🔋 [__Worker Middleware__][middleware] --- A suite of standalone HTTP server-side middleware with TypeScript support\n- 📄 [__Worker HTML__][html] --- HTML templating and streaming response library\n- 📦 [__Storage Area__][kv-storage] --- Key-value store abstraction across [Cloudflare KV][cloudflare-kv-storage], [Deno][deno-kv-storage] and browsers.\n- 🆗 [__Response Creators__][response-creators] --- Factory functions for responses with pre-filled status and status text\n- 🎏 [__Stream Response__][stream-response] --- Use async generators to build streaming responses for SSE, etc...\n- 🥏 [__JSON Fetch__][json-fetch] --- Drop-in replacements for Fetch API classes with first class support for JSON.\n- 🦑 [__JSON Stream__][json-stream] --- Streaming JSON parser/stingifier with first class support for web streams.\n\nWorker Tools also includes a number of polyfills that help bridge the gap between Worker Runtimes:\n- ✏️ [__HTML Rewriter__][html-rewriter] --- Cloudflare's HTML Rewriter for use in Deno, browsers, etc...\n- 📍 [__Location Polyfill__][location-polyfill] --- A `Location` polyfill for Cloudflare Workers.\n- 🦕 [__Deno Fetch Event Adapter__][deno-fetch-event-adapter] --- Dispatches global `fetch` events using Deno’s native HTTP server.\n\n[router]: https://workers.tools/router\n[middleware]: https://workers.tools/middleware\n[html]: https://workers.tools/html\n[kv-storage]: https://workers.tools/kv-storage\n[cloudflare-kv-storage]: https://workers.tools/cloudflare-kv-storage\n[deno-kv-storage]: https://workers.tools/deno-kv-storage\n[kv-storage-polyfill]: https://workers.tools/kv-storage-polyfill\n[response-creators]: https://workers.tools/response-creators\n[stream-response]: https://workers.tools/stream-response\n[json-fetch]: https://workers.tools/json-fetch\n[json-stream]: https://workers.tools/json-stream\n[request-cookie-store]: https://workers.tools/request-cookie-store\n[extendable-promise]: https://workers.tools/extendable-promise\n[html-rewriter]: https://workers.tools/html-rewriter\n[location-polyfill]: https://workers.tools/location-polyfill\n[deno-fetch-event-adapter]: https://workers.tools/deno-fetch-event-adapter\n\nFore more visit [workers.tools](https://workers.tools).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworker-tools%2Fhtml-rewriter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fworker-tools%2Fhtml-rewriter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworker-tools%2Fhtml-rewriter/lists"}