Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

chrome-extension-messaging-tests

БесплатноБез исполняемых скриптовНе проверен

Use when a Chrome extension's messages reach no listener, sendResponse never fires, a port disconnects mid-test, or a web page's access must be proven. Tests…

testlandот testland★ 18 звёзд на GitHub

Об этом скилле

chrome-extension-messaging-tests

Overview

Extension components run in separate contexts (content script, service worker, popup, options page, an external web page, a native host process) and can only reach each other through the messaging APIs described on the Chrome Extensions message passing page. That page defines five distinct shapes, each with its own failure mode:

  1. One-shot runtime messages inside one extension (chrome.runtime.sendMessage).
  2. One-shot tabs messages into a content script (chrome.tabs.sendMessage).
  3. Long-lived ports (chrome.runtime.connect).
  4. Cross-extension and web-page messages, gated by externally_connectable.
  5. Native messaging (chrome.runtime.connectNative).

Most "the feature silently does nothing" bugs in an extension are one of these five failing quietly: a channel closed before the response, a message sent to a tab with no matching content script, a port dropped by a suspended service worker, or an origin missing from an allow-list. Tests here make each of those loud.

Scope boundary

This skill owns assertions about messages once an extension is installed and running: who can send, who receives, what the response contract is, when a channel closes, and what a payload is allowed to contain.

It deliberately does not cover getting the extension installed, reloaded, or refreshed after a code edit. Those are a separate job with a separate symptom: an install problem shows up as an extension that is absent or shows an error before any test runs, while everything here shows up as a running extension whose messages go nowhere. Assume the extension under test is loaded and its ID is known before applying anything below.

When to use

  • sendMessage resolves undefined or the callback never fires, and you need a test that pins down which side dropped the channel.
  • A popup action does nothing on the page: the message may never be reaching the content script.
  • A long-lived connection dies partway through a session and you need to distinguish a deliberate disconnect() from an unloaded frame.
  • A companion web site must talk to the extension and the externally_connectable allow-list has to be proven correct before publishing.
  • A native helper application is part of the product and CI has to prove the host is reachable.

How to use

  1. Identify the shape. Map the failing (or new) path to one of the five messaging shapes in the Overview - one-shot runtime, one-shot tabs, long-lived port, external / web-page, or native.
  2. Confirm the extension is running. Install / reload is out of scope (see Scope boundary); assume the extension is loaded and its ID is known before writing an assertion.
  3. Write the sender / listener pair for that shape. The two one-shot forms are in Authoring below; ports and the cross-boundary surfaces are in the linked references.
  4. Assert the full response object with an equality matcher, never toBeDefined() - the failure this API produces most often is an undefined-shaped response that toBeDefined() passes on.
  5. Apply the payload guardrails. Build fixtures from JSON-representable values only, and route on a message-type field so exactly one onMessage listener owns each type.
  6. Re-check the draft against the Anti-patterns table before committing.

Authoring

1. One-shot runtime messages

Per cr-msg, the sender awaits a promise and the listener responds:

// Sender (content script, popup, or options page)
const response = await chrome.runtime.sendMessage({ greeting: 'hello' });

// Listener (service worker)
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
  if (message.greeting !== 'hello') return;
  fetch('https://example.com')
    .then(r => sendResponse({ statusCode: r.status }));
  return true;  // hold the channel open for the async sendResponse
});

The return true is load-bearing. Per cr-msg, to respond asynchronously using sendResponse() you must return "a literal true (not just a truthy value)". Returning a truthy non-literal, or returning nothing, closes the channel and the sender's promise settles without the response.

From Chrome 148 a listener may instead return a promise whose resolved value becomes the response, per cr-msg. The same page notes promise support "is not enabled in extension script contexts if the extension extends DevTools with a devtools page", so a DevTools-extending extension must keep using the return true form.

The async-listener trap. An async listener implicitly returns a promise, which is not the literal true that cr-msg requires. On a Chrome older than 148, or in a DevTools-extending extension, that promise is ignored and the channel closes. Author either a non-async listener with return true, or an `async

Полный SKILL.md на GitHub

Установить chrome-extension-messaging-tests в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

.tessl-plugin/plugin.jsonreferences/cross-boundary-messaging.mdreferences/long-lived-ports.md

FAQ

Что делает скилл chrome-extension-messaging-tests?

Use when a Chrome extension's messages reach no listener, sendResponse never fires, a port disconnects mid-test, or a web page's access must be proven. Tests runtime.sendMessage, tabs.sendMessage, long-lived ports, externally_connectable and native messaging on a running extension.

Как установить скилл chrome-extension-messaging-tests?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл chrome-extension-messaging-tests запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить chrome-extension-messaging-tests с