[pull] main from MetaMask:main#522
Merged
Merged
Conversation
…-integrations) (#26026) ## **Description** Part 4/4 of #25767 — **Code owner: wallet-integrations** > **Independent** — can merge in any order. Removes `updateDataRecordingFlag` from the MetaMetrics mock in `ethereum-chain-utils.test.ts`. The production code (`ethereum-chain-utils.js`) only calls `MetaMetrics.getInstance().trackEvent()` — it never references `updateDataRecordingFlag`, making this mock property dead code. **What changed:** - **`ethereum-chain-utils.test.ts`** — removed `updateDataRecordingFlag: jest.fn()` from the `MetaMetrics.getInstance()` mock (1 line deleted). ## **Changelog** CHANGELOG entry: null ## **Related issues** This one is fixing the issue (PR 4 on 4): Fixes: #25767 Fixes: https://consensyssoftware.atlassian.net/browse/MCWP-297 ## **Manual testing steps** N/A — test-only change. ## **Screenshots/Recordings** N/A — test-only change. ### **Before** N/A ### **After** N/A ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I've included tests if applicable - [x] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I've applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Test-only cleanup that removes dead mocking with no runtime behavior changes. > > **Overview** > Cleans up the `switchToNetwork` analytics test by removing the unused `updateDataRecordingFlag` stub from the `MetaMetrics.getInstance()` mock in `ethereum-chain-utils.test.ts`. > > No production logic changes; the test now only mocks `trackEvent`, matching actual usage in `ethereum-chain-utils.js`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit c38c8c6. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
## **Description** On Android, tapping a `target="_blank"` link (e.g. the "Stake" button on lido.fi) in the in-app browser opens the URL in Chrome instead of loading it within the MetaMask browser. This does not happen on iOS. **Root cause:** The `@metamask/react-native-webview` library handles `target="_blank"` differently per platform when the `onOpenWindow` prop is not provided: - **iOS** has a built-in fallback in `createWebViewWithConfiguration` that loads the URL in the same WKWebView. - **Android** has no such fallback. With `setSupportMultipleWindows` defaulting to `true`, the native `RNCWebChromeClient.onCreateWindow` creates a bare `WebView` with no custom `WebViewClient`. Since `mHasOnOpenWindowEvent` is `false`, the URL is loaded in this bare WebView which has no UI container, causing Android to delegate to the system browser (Chrome). **Fix:** Added an `onOpenWindow` handler to the WebView in `BrowserTab` that intercepts `target="_blank"` navigations and loads the URL in the current tab via `window.location.href`. This matches the existing iOS fallback behavior and makes both platforms consistent. The handler reuses the same `sanitizeUrlInput` + `injectJavaScript` pattern already used elsewhere in the file for deeplink browser callbacks. ## **Changelog** CHANGELOG entry: Fixed an Android-only bug where `target="_blank"` links in the in-app browser opened in Chrome instead of loading within MetaMask ## **Related issues** Fixes: <!-- Add issue number if applicable --> Jira Ticket: https://consensyssoftware.atlassian.net/browse/MCWP-321 ## **Manual testing steps** ```gherkin Feature: In-app browser target="_blank" link handling Scenario: user taps a target="_blank" link on Android Given the user has the MetaMask app open on Android And the user navigates to https://lido.fi in the in-app browser When user taps the "Stake" button (which is an <a target="_blank"> link to https://stake.lido.fi) Then the URL loads within the MetaMask in-app browser And the user is NOT redirected to Chrome or any external browser Scenario: user taps a target="_blank" link on iOS Given the user has the MetaMask app open on iOS And the user navigates to https://lido.fi in the in-app browser When user taps the "Stake" button (which is an <a target="_blank"> link to https://stake.lido.fi) Then the URL loads within the MetaMask in-app browser (same behavior as before the fix) Scenario: user taps a regular link (no target="_blank") Given the user has the MetaMask app open on either platform And the user navigates to any dApp in the in-app browser When user taps a regular link without target="_blank" Then the link navigates normally within the in-app browser (no regression) ``` ## **Screenshots/Recordings** ### **Before** <!-- [screenshots/recordings showing Chrome opening on Android when tapping target="_blank" link] --> ### **After** <!-- [screenshots/recordings showing URL loading within in-app browser on Android] --> ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I've included tests if applicable - [x] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I've applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [x] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [x] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Localized to in-app browser WebView navigation; behavior change is straightforward and covered by new unit tests, with minimal impact outside `target="_blank"` handling. > > **Overview** > Fixes Android in-app browser behavior where `target="_blank"` links / `window.open()` could escape to the system browser by adding an explicit `onOpenWindow` handler that redirects the current WebView via injected `window.location.href` (with `sanitizeUrlInput`). > > Updates tests to mock the WebView ref `injectJavaScript`, adds coverage for `onOpenWindow` behavior (including quote sanitization and empty URL), and refreshes the BrowserTab snapshot to include the new prop. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 744973c. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.4)
Can you help keep this open source service alive? 💖 Please sponsor : )