# WebView

**imToken** 内置的 WebView 使用平台的原生内核，行为与 *MetaMask* 完全兼容，同时还提供开源 SDK，帮助你改进 Web 应用。你可以随时将 DApp 无缝迁移到 imToken WebView 环境中，或者完善你的网站，使其在 imToken 应用中获得更好的体验。

{% hint style="info" %}
WebView 指的是在 imToken 应用中运行 DApp 或 Web App 的上下文环境。
{% endhint %}

## 主要功能

### Providers 相关

* 与 *MetaMask* 完全兼容，可直接迁移 *Ethereum DApp* 在 imToken 应用内使用。
* 基于 [EIP1102](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1102.md) 标准，所有 DApp 必须按照 *EIP-1102* 标准才能获取账户信息，进行其他操作。
* 兼容 *Scatter*，你可以基于 *Scatter* 开发 EOS DApp。对于 `scatter-js`，支持不高于 `2.3.8` 版本的`scatterjs-core` 。
* 完整支持 EIP-3085，请查看 [RPC 文档](https://imtoken.gitbook.io/developers/zh/products/rpcs#wallet_addethereumchain) 了解更多。
* 不会在环境中自动注入 `web3.js` ，具体请查看 [版本说明](https://imtoken.gitbook.io/developers/zh/products/release-changes#bu-zai-zhu-ru-web-3-js)。
* 初始化 Provider 等相关操作可参考 [RPC 文档](https://imtoken.gitbook.io/developers/zh/products/rpcs#jie-shao)。

### 国际化

如果你的 DApp 应用支持多种语言，你可以通过以下方式确认当前的语言环境。(选择其中之一)

* **Request Header** - 在用户使用 DApp 时，任何 HTTP 请求的头部都会增加 `accept-language` 字段，值取决于当前 imToken 应用的语言环境 (来自用户设置)。如： `Accept-Language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,*;q=0.6`。
* **URL Query** - 页面在 imToken 内打开时 (使用 WebView)，URL 的末尾会增加 `query` 参数，如：

  `https://ens.token.im/?locale=en-US`。
* **APIs** - 通过 imToken 应用标准的 SDK 工具所提供的 API 来获取语言环境，请参考文档中的 `getCurrentLanguage`。

### 调试

你可以在 DApp URL 上追加 Query 参数 `__debug` 来打开调试功能。当 DApp 正确的设置此参数后，WebView 会在页面的右下角中插入一个调试面板。(类似于 Chrome 的 Debug 面板)

### DeepLink

如果你的 Web 应用运行于**移动设备**时，可以通过 *DeepLink* 调用并转向至 imToken 应用，在 imToken 应用 内部也可使用。具体请参考 [DeepLink](https://imtoken.gitbook.io/developers/zh/products/deep-linking) 文档。

### Wallet Connect

如果你的 DApp 运行于**桌面端或外部浏览器**时，不便使用 DeepLink 调用 imToken 应用，此时 Wallet Connect 可以帮助你连接到 imToken 应用。学习如何使用 Wallet Connect 建立连接与通信，请浏览我们的 [Wallet Connect 章节](https://imtoken.gitbook.io/developers/zh/deep-linking#wallet-connect-zhi-chi)。

### 预加载配置

当你的 Web 应用 (包含 DApp) 处于加载中时，我们也支持提供更优雅的展示方案以确保您的 Web 应用始终有最好的用户体验。阅读 [URL 预加载配置文档](https://imtoken.gitbook.io/developers/zh/products/webview/preload-url-options) 了解更多。

### SDK APIs

`@consenlabs-fe/webview` 是可以帮助你在 imToken 应用内获得更好体验的开源 SDK，我们可以借助此 SDK 完成对于 imToken WebView 的深度定制与开发。阅读 [SDK API 文档](https://imtoken.gitbook.io/developers/zh/products/sdk#jie-shao) 了解更多。&#x20;

{% hint style="info" %}
imToken WebView SDK 用于 imToken 应用内的功能支持，如果修改标题、调用原生 UI 等。
{% endhint %}

### Ethereum RPCs

请在 RPC 文档 中查看我们所有支持的 [Ethereum RPC 标准接口](https://imtoken.gitbook.io/developers/zh/products/rpcs#jie-shao)。

### 如何判断 imToken 环境

* 你可以直接使用 `!!window.imToken` 或是 `window.ethereum.isImToken`，返回 `ture` 或是 `false` 以确认当前是否处于 imToken 环境。
* 直接使用 [WebView SDK](https://imtoken.gitbook.io/developers/zh/products/sdk#istokenenv) 。

### 如何开始

如果你还没有 DApp 的开发经验，可以试试阅读我们为你准备的 [快速上手](https://imtoken.gitbook.io/developers/zh/products/webview/development-guide-for-imtoken-dapp) 文档。


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://imtoken.gitbook.io/developers/zh/products/webview.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
