> For the complete documentation index, see [llms.txt](https://docs.convai.com/api-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-pixel-streaming-embed/cdn-umd-script.md).

# 使用脚本标签嵌入体验

通过 script 标签从 CDN 加载 Pixel Streaming Embed 包，并在普通 HTML 页面中渲染已发布的体验，无需构建步骤。

通过从 CDN 加载软件包的 UMD 构建版本，在纯 HTML 页面中呈现已发布的 Convai Pixel Streaming 体验。如果网站没有打包工具，请使用此页面。最后，页面会显示该体验的启动界面。

### 前提条件

* 已发布体验的 ID，以及一种授权方式：用于返回 Convai 身份验证令牌的服务器路由，或已添加到 Convai 允许列表中的域名。请参阅 [发布并授权体验](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-pixel-streaming-embed/whitelisting-and-publishing-an-experience.md).
* 用于提供此页面的 Web 服务器，因为示例会从同一服务器上的路由获取令牌。

### 添加脚本和容器

UMD 构建版本位于 `dist/core/convai-embed.umd.js`。它是自包含的，并定义了一个全局变量： `PixelStreamCore`，其 `PixelStreamClient` 属性是用于呈现体验的类。客户端会填满其容器，因此请为容器设置尺寸：

{% code title="index.html" %}

```html
<!doctype html>
<html>
  <body>
    <div id="experience" style="width: 100%; height: 600px"></div>

    <script src="https://unpkg.com/@convai/experience-embed/dist/core/convai-embed.umd.js"></script>
    <script>
      fetch('/api/convai-token')
        .then((response) => response.json())
        .then((body) => {
          window.experience = new PixelStreamCore.PixelStreamClient({
            container: document.getElementById('experience'),
            expId: 'YOUR_EXPERIENCE_ID',
            authToken: body.token,
          });
        });
    </script>
  </body>
</html>
```

{% endcode %}

此示例会从服务器上的路由 `/api/convai-token`获取身份验证令牌。如果 Convai 已将你的域名加入允许列表，则省略 `authToken` ，并直接创建客户端，无需获取任何内容。

{% hint style="warning" %}
上面的 URL 始终会加载最新版本。若要固定使用某个版本，请在 URL 中添加版本号，例如 `@convai/experience-embed@` 后接版本号。 <code class="expression">space.vars.experience\_embed\_version</code>.
{% endhint %}

### 控制体验

客户端会显示 **点击以开始体验** 界面；用户点击后，体验便会启动。体验加载完成后，可通过你自己的控件调用其方法：

```html
<button onclick="experience.enableCamera()">开启摄像头</button>
<button onclick="experience.disableCharacterAudio()">将角色静音</button>
<button onclick="experience.muteMicrophone()">将麦克风静音</button>
```

请参阅 [Pixel Streaming Embed API 参考](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-pixel-streaming-embed/api-reference.md#pixelstreamclient-methods) ，了解所有方法、选项和回调。

### 验证嵌入

通过 Web 服务器打开页面。

{% hint style="success" %}
容器中会显示 **点击以开始体验**；点击后即可显示该体验。
{% endhint %}

如果容器中显示 `Please contact convai to get <origin> whitelisted!` ，或显示与身份验证令牌相关的消息，请参阅 [故障排除](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-pixel-streaming-embed/react-typescript.md#troubleshooting)；原因相同。

### 后续步骤

{% content-ref url="/pages/2ee929ec767e1d00ab78c4c9e94458676bd7a970" %}
[使用 JavaScript 模块嵌入体验](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-pixel-streaming-embed/vanilla-javascript-es-modules.md)
{% endcontent-ref %}

{% content-ref url="/pages/87b57936662c69d8802f20f500191b181163cf02" %}
[Pixel Streaming Embed API 参考](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-pixel-streaming-embed/api-reference.md)
{% endcontent-ref %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-pixel-streaming-embed/cdn-umd-script.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
