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★ 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:
- One-shot runtime messages inside one extension
(
chrome.runtime.sendMessage). - One-shot tabs messages into a content script
(
chrome.tabs.sendMessage). - Long-lived ports (
chrome.runtime.connect). - Cross-extension and web-page messages, gated by
externally_connectable. - 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
sendMessageresolvesundefinedor 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_connectableallow-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
- 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.
- 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.
- 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.
- Assert the full response object with an equality matcher, never
toBeDefined()- the failure this API produces most often is anundefined-shaped response thattoBeDefined()passes on. - Apply the payload guardrails. Build fixtures from
JSON-representable values only, and route on a message-type field so
exactly one
onMessagelistener owns each type. - 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
Установить chrome-extension-messaging-tests в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
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), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic