> For the complete documentation index, see [llms.txt](https://docs.cobrowse.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cobrowse.io/sdk-features/advanced-features/intercepting-mobile-sdk-network-requests.md).

# Intercepting mobile SDK network requests

{% tabs %}
{% tab title="iOS" %}
You can provide the `URLSession` that will be used for all network requests made by the Cobrowse SDK.

```swift
CobrowseIO.instance().urlSession = \\ Your URLSession object
```

By setting a delegate on the provided `URLSession` object it will be told of any network request. You can then take action such as cancelling the task to block the network request from being made.

```swift
class CustomURLSessionDelegate: NSObject, URLSessionTaskDelegate {
    
    func urlSession(_ session: URLSession, didCreateTask task: URLSessionTask) {
        let allowedHosts = ["api.cobrowse.io"]
        
        guard let host = task.currentRequest?.url?.host, !allowedHosts.contains(host)
            else { return }
        
        print("Blocking data task for host: \(host)")
        task.cancel()
    }
}
```

{% hint style="info" %}
Requires iOS 15+ macOS 12+
{% endhint %}
{% endtab %}

{% tab title="Android" %}
Cobrowse SDK uses [OkHttp](https://github.com/square/okhttp) for network communication. You can provide an `OkHttpClient` instance that will be used for all HTTP requests made by the Cobrowse SDK.

```kotlin
CobrowseIO.instance().okHttpClient(
    OkHttpClient.Builder()
        .addInterceptor(LoggingInterceptor())
        .build()
)
```

By setting an interceptor on the provided `OkHttpClient` object it will be told of any network request. You can then take action such as throwing an exception to block the network request from being made.

```kotlin
class LoggingInterceptor : Interceptor {
    companion object {
        private val allowedHosts = setOf(".cobrowse.io")
    }

    override fun intercept(chain: Interceptor.Chain): Response {
        val request = chain.request()
        val host = request.url().host()
        if (allowedHosts.any { host.endsWith(it) }) {
            return chain.proceed(request)
        } else {
            throw IOException("This request is not allowed: " + request.url())
        }
    }
}
```

{% endtab %}
{% endtabs %}


---

# 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 dynamically by asking a question.

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

```
GET https://docs.cobrowse.io/sdk-features/advanced-features/intercepting-mobile-sdk-network-requests.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
