Skip to content

Commit 17b9874

Browse files
Teng-Web3seaona
andauthored
fix: Failed to construct URL: Invalid URL at new URL (#31502)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** When go to certain websites the background console show error: "TypeError: Failed to construct 'URL': Invalid URL at new URL." Root Cause: Sometimes the website's initiator is "null", not null, so we will create URL object with Illegal string("null"): ![屏幕截图 2025-04-01 230234](https://github.com/user-attachments/assets/ce7ff859-19cb-471b-9804-13221b38e1df) Solution: Filter out "null" strings <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/31502?quickstart=1) ## **Related issues** Fixes: #31465 ## **Manual testing steps** 1. Open the browser 2. Open the background console 3. Go to https://soundcloud.com/ 4. Check if the error "TypeError: Failed to construct 'URL': Invalid URL at new URL" shown. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** ![before](https://github.com/user-attachments/assets/fd681a83-e9c2-4bb2-b139-d8742f09d340) <!-- [screenshots/recordings] --> ### **After** ![after](https://github.com/user-attachments/assets/ba4462c7-6cea-4f67-b4be-179f06c03231) <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/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 - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/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. Co-authored-by: seaona <[email protected]>
1 parent 853f5a8 commit 17b9874

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

app/scripts/background.js

+1
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ function maybeDetectPhishing(theController) {
283283
// is shipped.
284284
if (
285285
details.initiator &&
286+
details.initiator !== 'null' &&
286287
// compare normalized URLs
287288
new URL(details.initiator).host === phishingPageUrl.host
288289
) {

0 commit comments

Comments
 (0)