Cobrowse.io Docs
  • Getting started
  • SDK Installation
    • Web
    • iOS
    • Android
    • React Native
    • Flutter
    • .NET Mobile
    • macOS
    • Windows
  • SDK Features
    • Account config
    • Identify your devices
    • Use 6-digit codes
    • Redact sensitive data
    • Viewing PDFs
    • Universal Cobrowse
    • Customize the interface
      • Active session controls
      • 6-digit code screen
      • User consent dialog
      • Remote control consent dialog
      • Full device consent dialog
      • Localization / translation
    • Initiate sessions with push
    • Listening for events
    • Full device capabilities
      • Full device screen sharing
      • Full device remote control
      • Managing full device mode
    • Advanced configuration
      • Starting and stopping the SDK
      • Declaring capabilities
      • Intercepting mobile SDK network requests
      • Web
        • IFrames support
        • IE 11 polyfills
        • Cross-domain session support
        • Ignore Views
      • iOS
        • Alternate render method
        • Custom touch handling
      • Android
        • Backporting TLS to older Android versions
  • Agent-side integrations
    • Agent-side overview
    • Platform integrations
      • Zendesk
      • Salesforce
        • Migrating from legacy to v2
        • Salesforce (Legacy)
      • Genesys
        • Genesys Cloud
        • Engage Workspace Web Edition (WWE)
        • Engage Workspace Desktop Edition (WDE)
      • Intercom
      • Freshworks
      • Talkdesk
      • NICE
    • Custom integrations
    • Agent SDK
      • API Reference
      • Sample code snippets
    • Authentication (JWTs)
      • JWT Policies
    • Authentication (SAML 2.0)
    • IFrame embeds
  • Enterprise self-hosting
    • Self-hosting overview
    • Docker Compose
    • Helm chart
      • Image Pull Secret
      • Environment Variables
      • Optional recording components
      • Pod Annotations
    • AWS terraform
      • AWS metrics configuration
    • Azure terraform
      • Azure metrics configuration
    • GCP terraform
      • GCP metrics configuration
    • Sizing guidelines
    • Running your instance
      • Adding a superuser
      • Limiting account creation
      • Limiting magic link recipients
      • Configuring SMTP
      • Managing your deployment
    • Monitoring your instance
      • Available metrics
      • Self-Hosted Prometheus
    • Advanced configuration
      • Air gap configuration
      • Pin web SDK version
      • L7 firewall configuration
      • Docker proxy configuration
    • Troubleshooting
Powered by GitBook
On this page

Was this helpful?

  1. SDK Features
  2. Advanced configuration

Intercepting mobile SDK network requests

Have greater control over networking requests made by the mobile SDKs.

PreviousDeclaring capabilitiesNextWeb

Last updated 2 months ago

Was this helpful?

You can provide the URLSession that will be used for all network requests made by the Cobrowse SDK.

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.

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()
    }
}

Requires iOS 15+ macOS 12+

Cobrowse SDK uses for network communication. You can provide an OkHttpClient instance that will be used for all HTTP requests made by the Cobrowse SDK.

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.

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())
        }
    }
}
OkHttp