# Проверка состояния

Сперва, вам необходимо повесить обработчик событий `onMessage` на `window`, затем вставить на страницу код `iframe` для получения сообщений посылаемых [расширением](/extension/about.md).

{% code overflow="wrap" lineNumbers="true" %}

```javascript
function checkExtension(e) {
  // отлавливаем все сообщения на странице и фильтруем, нас интересуют только сообщения от api.waix.ru
  if (e.origin.indexOf('api.waix.ru') < 0)
    return;

  if (e.data.key) { // false or true
    // key entered or not
  }
  if (e.data.user) {
    // user is active or not
  }
  if (location.host != e.data.domain) {
    // the Google Extension is being used by another company
  }
  if (!e.data.key || !e.data.user) {
    // the Google Extension installed but not used
  }
}

window.addEventListener("message", checkExtension, false);
```

{% endcode %}

Вставьте код `iframe` в место, где вы хотите проверять состояние расширения, например в личном кабинете пользователя. Если `iframe` отсутствует, вы не сможете перехватить событие сообщения `onMessage` для получения состояния.

{% code overflow="wrap" fullWidth="false" %}

```html
<iframe src="https://api.waix.ru/check.html" frameborder="0" height="0" style="overflow: hidden;"></iframe>
```

{% endcode %}

{% hint style="info" %}
Важное замечание, код скрипта JavaScript должен находиться перед iframe, чтоб избежать ситуации, когда iframe загрузится из кэша быстрее, чем успеет инициироваться код JS.
{% endhint %}


---

# 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://doc.waix.ru/extension/check.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.
