ホーム 格闘技 AI Running in the Browser — I Tried Running the Gemma 4 Browser Extension on Mac!

AI Running in the Browser — I Tried Running the Gemma 4 Browser Extension on Mac!

三浦 拓海 三浦 拓海 • 更新: • 公開: • 読了約 20 分
目次

An AI agent that runs entirely within your browser without sending any data to the cloud. That future is already here. In this article, I will explain to Mac users how to install and use the "Transformers.js Gemma 4 Browser Assistant," which runs Google's Gemma 4 model as a Chrome extension.

What you can do with this extension

na0ba05649efa

This Chrome extension is an AI agent that operates within the browser. By simply speaking to it in natural language, you can perform the following operations:

Tab Management
  • List open tabs — Retrieve the titles and URLs of all tabs

  • Switch tabs — "Move to the tab for [Subject]"

  • Open URL — Open a page in a new tab

  • Close tabs — Specify unnecessary tabs in natural language to close them

Web Page Understanding (RAG)
  • ask_website — Perform a semantic search on the current page's content. It finds the relevant section within the page to answer questions like "How much does this page cost?"

  • highlight_website_element — Highlight elements on the page. The agent visually points out "It's here."

Vector Search for Browsing History
  • find_history — Save browsing history to a vector database (IndexedDB) and search it using natural language. Allows for fuzzy searches like "the WebGPU article I read last week"

All processing is completed locally. There is absolutely no data transmission to external servers.

How it works — 3-layer architecture

This extension effectively utilizes three contexts of Chrome extensions.

ユーザー入力(サイドパネル)
    ↓ chrome.runtime.sendMessage
Background Service Worker(AIエンジン)
    ↓ Transformers.js + WebGPUで推論
    ↓ ツール実行(タブ操作、ページ検索など)
    ↓ chrome.tabs.sendMessage
Content Script(ページ操作)
    ↓ DOM解析・ハイライト表示
    ↓ 結果をBackgroundに返却
サイドパネル(応答を表示)

Background Service Worker is the AI's brain. Once the Gemma 4 model is loaded, it is shared across all tabs and panels. A key point is that you don't need to reload the multi-gigabyte model every time.

Side Panel is a chat UI built with React. Unlike a popup, it stays open while you browse, so the context of the conversation is not lost.

Content Script runs on each web page, parses the DOM structure (headings, paragraphs, lists), and passes it to the background. This is the foundation of the RAG feature.

Model Used

This extension uses two different models.

Gemma 4 E2B Text Generation (Agent Reasoning)
Approx. 1.5GB q4f16 quantization

all-MiniLM-L6-v2 Embedding Vector Generation (RAG/History Search)
Approx. 23MB fp32

Gemma 4 E2B is the most compact model in the Gemma 4 family released by Google. It is converted to ONNX format and can perform high-speed inference on WebGPU via Transformers.js v4. Through q4f16 quantization, the model size is significantly compressed while maintaining practical quality.

Prerequisites — Running on a Mac

Verifying WebGPU Support

The conditions for using WebGPU on a Mac are as follows.

  • Apple Silicon (M1 or later): All support WebGPU. Because it uses Unified Memory, it runs fast even without a discrete GPU

  • Intel Mac: Supported on macOS Ventura (13.0) or later + Chrome 113 or later

How to Verify
  1. Enter chrome://gpu in the Chrome address bar

  2. Look for the "WebGPU" section

  3. "Hardware accelerated" should be displayed

Memory Guidelines

Apple Silicon's Unified Memory allows the CPU and GPU to share the same memory pool. Since Gemma 4 E2B (q4f16) is about 1.5GB, it runs without issues on a 16GB Mac. However, since it also depends on other applications, having more memory available will provide a smoother experience.

Required Software
  • Chrome 113 or later (Recommended: Latest version)

  • Node.js 18 or later

  • pnpm package manager

If pnpm is not installed:

# Homebrewの場合
brew install pnpm
またはnpmから
npm install -g pnpm

Installation Steps

Step 1: Clone the repository
git clone https://github.com/nicostrem/gemma4-browser-extension.git
cd gemma4-browser-extension
Step 2: Install dependencies
pnpm install

Dependency packages including Transformers.js v4 will be installed.

Step 3: Build
pnpm run build

TypeScript compilation and Vite bundling will be executed, and the extension artifacts will be generated in the dist folder.

Step 4: Load into Chrome
  1. Enter chrome://extensions/ in the Chrome address bar

  2. Turn on "Developer mode" in the top right

  3. Click "Load unpacked" extension

  4. Select the dist folder generated earlier

Step 5: First launch — Model download
  1. Click the extension icon in the top right of Chrome

  2. The side panel will open and the chat interface will be displayed

  3. The model will start downloading automatically the first time (Gemma 4 E2B: approx. 1.5GB + all-MiniLM-L6-v2: approx. 23MB)

The download happens only once. From then on, it will be cached in Chrome's storage and loaded instantly.

Let's try it out

Once the model has finished loading, talk to the chat in the side panel using natural language.

Example of tab manipulation
今開いているタブを全部教えて

The agent calls the get_open_tabs tool and lists the titles and URLs of all tabs.

GitHubのタブに切り替えて

Switch to a tab actively using the go_to_tab tool.

Ask questions about web pages
このページの主な機能は何?

The ask_website tool performs a semantic search of the page content, finds relevant paragraphs, and generates an answer.

Search browsing history
先週見たTransformers.jsの記事を探して

The find_history tool searches the vector database and returns history that is semantically similar rather than just keyword matches.

Development mode

Use development mode if you want to test while modifying the extension code.

pnpm run dev

Vite's watch mode detects file changes and automatically rebuilds. After building, click the "Reload" button on the Chrome extensions page to apply the changes.

Troubleshooting

If "WebGPU is not supported" is displayed
  • Try enabling chrome://flags/#enable-unsafe-webgpu

  • Please update Chrome to the latest version

  • For Intel Macs, macOS Ventura is required

Model download stops midway
  • Check your network connection. The model is downloaded from the Hugging Face Hub

  • Try disabling and re-enabling the extension on the Chrome extensions page and reloading

Inference is slow
  • Try closing other tabs that use the GPU (such as WebGL/WebGPU demos)

  • You can check GPU usage in the Performance tab of Chrome DevTools

Build errors occur
  • Node.js 18 or later is required. Check your version with node -v

  • Please confirm that pnpm install has completed successfully.

About Privacy

The biggest feature of this extension is complete on-device processing.

  • Model inference is executed entirely within the browser using WebGPU.

  • The vector database of browsing history is saved to IndexedDB (local only).

  • There are no requests to external APIs (excluding the initial model download from Hugging Face Hub).

Unlike cloud-based AI assistants, page content and browsing history are never sent to a server. You can use it with peace of mind for internal company pages or personal browsing.

Can be used for translation

You can also use it for translation like this.

It could also be used to make your own custom extensions smarter.

If you encounter any issues, check DevTools > Application > Service Workers.

Summary — The Browser Becomes an Execution Environment for AI Agents

Thanks to the evolution of WebGPU and Transformers.js, the era has arrived where AI models with billions of parameters can run practically within the browser.

  • Apple Silicon Mac — Runs without worrying about dedicated GPU memory thanks to Unified Memory.

  • Completely Local — No data transmission, complete privacy protection.

  • Agent-based — Not just a chat, but autonomously utilizes tools like tab manipulation and page searching.

  • Open Source — You can read the code to learn and also modify it.

The convenience of cloud AI and the privacy of local AI. This balance is realized in the familiar form of a browser extension. Try running it on your Mac first.

Repository: nicostrem/gemma4-browser-extension
Model used: onnx-community/gemma-4-E2B-it-ONNX


同じカテゴリの記事

三浦 拓海
コンテンツディレクター 三浦 拓海
プロフィールを見る →

映画と連続ドラマの公開情報を追う担当。配給会社のプレスシートと公式サイトの発表日を確認したうえで執筆します。

おすすめの関連記事