> ## Documentation Index
> Fetch the complete documentation index at: https://chainpatrol.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Overview

> Relay messages between browser extensions and web pages.

The `Relay` class is a utility for receiving messages from the ChainPatrol
warning page in your browser extension-based wallet/security app. You may
already have a message passing system in place in your browser extension, but
this class is provided as a convenience for those who do not, or if you want to
keep your message passing system separate from the ChainPatrol SDK.

## Usage

<CodeGroup>
  ```js Warning Page theme={null}
  import { Relay, Events } from "@chainpatrol/sdk";

  // Send a message to the extension
  Relay.send(Events.ContinueAtOwnRisk, { domain: "example.com" });
  ```

  ```js Content Script theme={null}
  import { Relay, Events } from "@chainpatrol/sdk";

  Relay.run([Events.ContinueAtOwnRisk]);
  ```

  ```js Background Script theme={null}
  import { Relay, Events } from "@chainpatrol/sdk";

  // Listen for messages from relay
  Relay.on(Events.ContinueAtOwnRisk, (data) => {
    // Do something with the event data
  });
  ```
</CodeGroup>

## How it works

In order for events from the warning page to be received by your browser extension,
the messages have to be relayed from the warning page to the content script, and then
from the content script to the background script.

<Frame>
  <img src="https://mintcdn.com/chainpatrol/oLEHOzLMXL0CWKrg/images/relay.png?fit=max&auto=format&n=oLEHOzLMXL0CWKrg&q=85&s=46c11a6ae67a98ddda8845bf77f3ea58" width="2235" height="1157" data-path="images/relay.png" />
</Frame>

Under the hood, the `Relay` class sets up the appropriate message listeners depending on
the scripting context (ie. `window.postMessage` in the warning page, `chrome.runtime.sendMessage` in the content
and background scripts), and makes sure that all messages are passed along to all
subscribers.

***

## Static Methods

### [send()](./static-methods/send)

Sends an event to listeners.

### [run()](./static-methods/run)

Sets up listeners for events and forwards events to all other listeners.

### [on()](./static-methods/on)

Adds a listener for an event.
