Skip to content

Conversation

@christopherferreira9
Copy link

@christopherferreira9 christopherferreira9 commented Feb 4, 2026

Summary

Add native E2E request interception support for Android WebView to enable routing all network requests through the mock server during E2E tests.

Motivation

During E2E testing, API calls made from the in-app browser (WebView) were not being intercepted by the mock server. This is because the existing mock server implementation patches fetch and XMLHttpRequest in the React Native JavaScript context (shim.js), but WebView runs in a separate browser context with its own network stack.
This PR adds native-level request interception on Android using shouldInterceptRequest, which intercepts ALL network requests from the WebView (including page navigation, resources, and API calls) and routes them through the mock server proxy.

Changes

Android Native Code
RNCWebViewClient.java:

  • Added mE2EMode and mMockServerUrl member variables
  • Added setE2EMode() and setMockServerUrl() public methods
  • Implemented shouldInterceptRequest() to intercept HTTP/HTTPS requests and route them through the mock server proxy (/proxy?url=...)
  • Added isLocalOrMockServerUrl() helper to bypass interception for localhost/mock server URLs (prevents infinite loops)

RNCWebView.java:
-Added setE2EMode() and setMockServerUrl() methods that forward to RNCWebViewClient

RNCWebViewManagerImpl.kt:

  • Added setE2EMode() and setMockServerUrl() functions

RNCWebViewManager.java (oldarch & newarch):

  • Added @ReactProp annotations for e2eMode (boolean) and mockServerUrl (String)

iOS Native Code
RNCWebViewImpl.h:

  • Added e2eMode and mockServerUrl properties (for future native implementation)

RNCWebViewManager.mm:

  • Added RCT_EXPORT_VIEW_PROPERTY for e2eMode and mockServerUrl

Note: iOS currently relies on JavaScript injection for fetch/XHR interception. Native iOS interception via NSURLProtocol can be added in a future PR if needed.

Usage

<WebView e2eMode={true} mockServerUrl="http://localhost:8000" // ... other props/>
When e2eMode is true and mockServerUrl is provided, the Android WebView will:

  1. Intercept all HTTP/HTTPS requests via shouldInterceptRequest
  2. Route them through {mockServerUrl}/proxy?url={encodedOriginalUrl}
    3 Return the proxied response to the WebView

Testing

  • Verified E2E tests can now intercept and mock WebView network requests
  • Verified non-E2E builds are unaffected (props default to false/null)
  • Verified localhost/mock server URLs are bypassed to prevent infinite loops

Related

Consumer PR: MetaMask/metamask-mobile#25652

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant