npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

writer-rewriter-polyfills

v1.0.0

Published

Polyfills for the Writer and Rewriter APIs, backed exclusively by the browser's LanguageModel API

Readme

Writer and Rewriter API Polyfills

Chrome is proposing to deprecate and remove the experimental Writer and Rewriter APIs. This package keeps window.Writer and window.Rewriter working by reimplementing them on top of window.LanguageModel, using the same system prompt templates Chrome used. Your calling code does not change.

The polyfills are backed exclusively by the LanguageModel implementation the browser itself provides, with no fallback behind them and no way to opt into one:

  • Writer.availability() and Rewriter.availability() resolve with 'unavailable' when window.LanguageModel is missing.
  • Writer.create() and Rewriter.create() reject with a NotSupportedError.

Why the APIs are going away

Both APIs were explored as task-specific abstractions and reached an origin trial, but the signal from that trial was consistent: developers preferred to implement writing and rewriting directly with the Prompt API (window.LanguageModel).

That preference is a reasonable one, because the two APIs were never more than templatized system prompts over the same on-device model the Prompt API exposes. Custom prompting reached the same results, or better ones, and base models have improved to the point where adjusting tone, length, and format needs no dedicated API. Retiring these thin abstractions frees up effort for task APIs where a dedicated model does earn its place, such as Summarizer and Translator, and for primitives that unlock things the platform cannot do yet, such as embeddings and tool calling.

Installation

npm install writer-rewriter-polyfills

There are no runtime dependencies.

Usage

Load a polyfill only where the native API is missing, so browsers that still ship it keep using it:

const polyfills = [];
if (!('Writer' in self)) {
  polyfills.push(import('writer-rewriter-polyfills/writer'));
}
if (!('Rewriter' in self)) {
  polyfills.push(import('writer-rewriter-polyfills/rewriter'));
}
await Promise.all(polyfills);

Importing the package root loads both at once:

import 'writer-rewriter-polyfills';

Then check availability before you offer the feature. Because there is no fallback behind it, 'unavailable' is the answer you should design for first:

const options = { tone: 'neutral', format: 'plain-text', outputLanguage: 'en' };

switch (await Writer.availability(options)) {
  case 'unavailable':
    // Either there is no window.LanguageModel, or it has no usable model for
    // these options. Fall back to whatever your app did before.
    showPlainEditor();
    break;
  case 'downloadable':
  case 'downloading':
    // The model still has to arrive. Ask first, then report progress below.
    showDownloadPrompt();
    break;
  case 'available':
    showWriterUi();
    break;
}

Creating a writer is unchanged, including the download monitor:

try {
  const writer = await Writer.create({
    ...options,
    sharedContext: 'An email to a colleague.',
    monitor: (m) => {
      m.addEventListener('downloadprogress', (e) => {
        progress.value = e.loaded;
        progress.max = e.total;
      });
    },
  });

  const draft = await writer.write('Tell her I will be late.');
  writer.destroy();
} catch (error) {
  if (error.name === 'NotSupportedError') {
    showPlainEditor();
  } else {
    throw error;
  }
}

Rewriter works the same way, with rewrite() in place of write():

const rewriter = await Rewriter.create({ tone: 'more-casual' });
const result = await rewriter.rewrite(
  'I am writing to inform you that I will be late.',
);
rewriter.destroy();

Both also stream, through writeStreaming() and rewriteStreaming():

const stream = writer.writeStreaming('Tell her I will be late.');
for await (const chunk of stream) {
  output.append(chunk);
}

API surface

The polyfills follow the documented APIs:

For complete examples, see demo-writer.html and demo-rewriter.html.

Running the demos locally

npm install
npm start

By default the demos force the polyfill even where the browser ships a native Writer or Rewriter, so the polyfill code path is the one being exercised. Add ?native to the URL to prefer native support where it exists.

To build the demos as a static site:

npm run build:demos

If you would rather not use the polyfill

Prompt the model yourself. The system prompt templates behind these APIs are in writer-prompt-builder.js and rewriter-prompt-builder.js. They are meant to be read, taken apart, and adapted: start from the template for the tone, format, and length you need, and drop the rest.

Those two files are generated from Chrome's own prompt dumps by scripts/writer-prompt-extractor.js and scripts/rewriter-prompt-extractor.js, so do not edit them by hand.

Tell us if this does not work for you

The proposal is not final, and the point of announcing it early is to find the use cases it would break. If you have been testing these APIs and the Prompt API or this polyfill falls short on quality, performance, or ergonomics, describe the case in the Writer and Rewriter APIs consultation form. Concrete examples carry the most weight, and we will follow up with a short technical conversation where one would help.

License

Apache 2.0