---
title: "How to Use Transformers.js in a Chrome Extension"
description: "Running local AI in a Chrome Manifest V3 extension works best when the background service worker hosts all Transformers.js models and agent state, while the side panel UI and content scripts act as thin clients over a typed messaging contract."
url: "https://swe.quest/articles/how-to-use-transformers-js-in-a-chrome-extension-565affa6c1396666"
canonical: "https://huggingface.co/blog/transformersjs-chrome-extension"
source: "Hugging Face"
published: "2026-04-23"
difficulty: "medium"
kind: "How-to"
reading_minutes: 8
tags: ["browsers","ai-agents","inference","llms","javascript"]
---

# How to Use Transformers.js in a Chrome Extension

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2026-04-23, 8 min read, How-to. Original: [https://huggingface.co/blog/transformersjs-chrome-extension](https://huggingface.co/blog/transformersjs-chrome-extension)

## Summary

Running local AI in a Chrome Manifest V3 extension works best when the background service worker hosts all Transformers.js models and agent state, while the side panel UI and content scripts act as thin clients over a typed messaging contract. The reference build (a Gemma 4 E2B browser assistant) uses Gemma 4 E2B (q4f16, WebGPU) for tool-calling reasoning and MiniLM embeddings for semantic search over pages and history. Inference in the background gives one model instance, one cache under the extension origin, and a responsive UI. The guide also covers parsing Gemma tool-call tokens into deterministic tool executions, splitting the internal model transcript from the UI transcript, and placing state by lifecycle across memory, chrome.storage and IndexedDB. Service workers can be suspended, so model runtime state should be recoverable, and Vite should produce one artifact per manifest entry point.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Browsers](https://swe.quest/tags/browsers.md) (Web & mobile)
- [AI agents](https://swe.quest/tags/ai-agents.md) (AI & ML)
- [Inference & serving](https://swe.quest/tags/inference.md) (AI & ML)
- [LLMs](https://swe.quest/tags/llms.md) (AI & ML)
- [JavaScript](https://swe.quest/tags/javascript.md) (Languages)

## Prerequisites

- Chrome extension Manifest V3 ([easy posts on Browsers](https://swe.quest/tags/browsers.md?difficulty=easy))
- JavaScript/TypeScript ([easy posts on JavaScript](https://swe.quest/tags/javascript.md?difficulty=easy))
- LLM tool calling basics ([easy posts on LLMs](https://swe.quest/tags/llms.md?difficulty=easy))

## Keywords

Transformers.js, Gemma 4, Manifest V3, Chrome extensions, WebGPU, all-MiniLM-L6-v2, ONNX, IndexedDB

## Related posts

- [Transformers.js v4: Now Available on NPM!](https://swe.quest/articles/transformers-js-v4-now-available-on-npm-60e5d316d3e108bd.md): Hugging Face · 2026-02-09 · Medium · 7 min read · Inference & serving, JavaScript, LLMs, Browsers, Build systems
  Transformers.js v4 ships on NPM with a new C++ WebGPU runtime built with the ONNX Runtime team, enabling WebGPU-accelerated models in browsers as well as Node, Bun and Deno.
- [Experimenting with the proposed Cross-Origin Storage API in Transformers.js](https://swe.quest/articles/experimenting-with-the-proposed-cross-origin-storage-api-in-transformers-js-f57157be2f20fb70.md): Hugging Face · 2026-06-23 · Medium · 13 min read · Browsers, Caching, Privacy, Inference & serving, JavaScript
  Browser cache partitioning (in Chrome, keying by Network Isolation Key plus URL) forces every origin running Transformers.js to re-download identical model weights and the ONNX Runtime Wasm file.
- [Gemma 3n fully available in the open-source ecosystem!](https://swe.quest/articles/gemma-3n-fully-available-in-the-open-source-ecosystem-6d60bf60e354184a.md): Hugging Face · 2025-06-26 · Medium · 9 min read · LLMs, Inference & serving, Computer vision, Speech & audio, Python
  Gemma 3n, Google's natively multimodal on-device model accepting text, image, audio and video, now runs in transformers, timm, MLX, llama.cpp (text only), Transformers.js/ONNX and Ollama.
- [My Journey to a serverless transformers pipeline on Google Cloud](https://swe.quest/articles/my-journey-to-a-serverless-transformers-pipeline-on-google-cloud-202ccbc112026927.md): Hugging Face · 2021-03-18 · Medium · 8 min read · Serverless, Inference & serving, Cloud platforms, Python, Containers
  A Hugging Face transformers sentiment-analysis pipeline (DistilBERT fine-tuned on SST-2) was deployed as a low-traffic microservice on Google Cloud Run after AI Platform Prediction (beta instability, checkpoint not a pure TensorFlow model) and App Engine (TensorFlow install failure, PyTorch handling only 2 requests per instance) fell short.
- [Total noob’s intro to Hugging Face Transformers](https://swe.quest/articles/total-noob-s-intro-to-hugging-face-transformers-c330cf4466509559.md): Hugging Face · 2024-03-22 · Easy · 11 min read · LLMs, Inference & serving, Python, Machine learning
  A beginner-oriented walkthrough of running Microsoft's Phi-2 language model with the Hugging Face Transformers library inside a JupyterLab notebook hosted on a Hugging Face Space with an NVIDIA A10G GPU.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
