# エミュレータでのテスト

## **エミュレータの準備**:

まずアプリケーションがローカルで動くエミュレータと通信できるように、特定の設定を追加する必要があります。これを行うためには、Firebaseの機能にアクセスするコードをアプリケーションに追加します。

以下のコードを、アプリの適切な場所（例えば初期設定を行う部分）に追加してください：

```javascript
// Firebaseにアクセスするコード
import { getFunctions, httpsCallable, connectFunctionsEmulator } from "https://www.gstatic.com/firebasejs/10.7.0/firebase-functions.js";
```

## **エミュレータへの接続設定**:

* `connectFunctionsEmulator` という関数を使用して、エミュレータが稼働しているURLとポート番号を指定します。
* この例では、エミュレータは `localhost` 上の `5001` 番ポートで稼働していますが、実際の環境に応じてURLとポート番号を変更してください。これらの情報は通常、プロジェクトの `firebase.json` ファイルの `emulators` セクションにあります。

次に、`connectFunctionsEmulator` 関数を使って、エミュレータが動いているURLとポートを指定します。

この例では、エミュレータは`localhost` の `5001` ポートを使っていますが、実際の環境に合わせて適切なURLとポートを設定してください。これらの情報は通常、プロジェクトの `firebase.json` ファイルの `emulators` セクションにあります。

以下のコードをアプリケーションに追加してください：

```javascript
// エミュレータに接続するコード
connectFunctionsEmulator(window.functions, 'localhost', 5001);
```

また、エミュレータはhttpでホスティングしていることに注意して下さい。そのため、アプリ側はhttpでの接続が可能で、かつ、Mixed Content Errorを 回避する必要があります。\
デバッグビルドしたアプリで確認する場合は、上記の \`localhost\` の部分は、お使いのIpアドレスになります。また、Androidであれば、config.xmlのandroidの設定に

```
<edit-config file="AndroidManifest.xml" target="/manifest/application" mode="merge">
  <application android:usesCleartextTraffic="true" />
</edit-config>
<preference name="scheme" value="http"/> 
```

が必要になります。\
\
これにより、アプリケーションはローカルのFirebaseエミュレータに接続し、Firebaseの関数をローカル環境でテストできるようになります。

これは開発過程で特に役立ち、実際のサーバーやデータベースを使う前にアプリケーションの動作を確認するのに適しています。


---

# 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://ja.docs.monaca.io/migration-guide/nifcloud/sukuriputo/emyurtadenotesuto.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.
