Skip to content

Conversation

@Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Jan 22, 2026

Description

During the setupController method in background.js, it will throw an error during initialization if any "controllers with persisted state" have something other than an object as their state (e.g. undefined or null or a primitive). This should be impossible due to type checks, but we're seeing it happen anyway.

This code has been updated to report the error and continue initialization without interruption. There is still a root cause here to fix, but we can address that in a follow-up PR (it may take more time to learn what the root cause is).

Open in GitHub Codespaces

Changelog

CHANGELOG entry: Prevent crash during initialization when some controller has invalid state.

Related issues

Fixes #39464

Manual testing steps

  • Fresh install, proceed through onboarding
  • After onboarding, open the loading.html page
  • In the dev console, run this:
    const old = await chrome.storage.local.get()
    await chrome.storage.local.set({ meta: old.meta, data: {...old.data, foo: 'foo', bar: null }})
    
  • Reload the extension, confirm that it still seems to work
    • I also used a breakpoint to confirm that the Sentry error was sent. You could confirm with the network tab instead (ensure you opt into metrics, otherwise it won't send)
  • Navigate to loading.html again, and run await chrome.storage.local.get() to confirm that the state was set correctly (foo and bar should be present). If not, try again.

Screenshots/Recordings

N/A

Pre-merge author checklist

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.

Note

Prevents initialization from crashing when a controller has invalid (non-object) state by reporting and skipping it.

  • Adds Sentry captureException import
  • In setupController (in background.js), guards each controller state: if null or not an object, report via captureException and continue; otherwise proceed with change detection/persistence

Written by Cursor Bugbot for commit 217ff83. This will update automatically on new commits. Configure here.

During the `setupController` method in `background.js`, it will throw
an error during initialization if any "controllers with persisted
state" have something other than an object as their state (e.g.
`undefined` or `null` or a primitive). This should be impossible due to
type checks, but we're seeing it happen anyway.

This code has been updated to report the error and continue
initialization without interruption. There is still a root cause here
to fix, but we can address that in a follow-up PR (it may take more
time to learn what the root cause is).

Fixes #39464
@metamaskbotv2
Copy link
Contributor

metamaskbotv2 bot commented Jan 22, 2026

Builds ready [d7f9f88]
UI Startup Metrics (1242 ± 112 ms)
PlatformBuildTypePageMetricTest Title (ms)Persona (ms)Mean (ms)Min (ms)Max (ms)Std Dev (ms)P 75 (ms)P 95 (ms)
ChromeBrowserifyStandard Home0--------
1--------
2--------
3--------
4--------
5--------
6--------
7--------
8--------
9--------
10--------
11--------
12--------
13--------
14--------
15--------
16--------
17--------
18--------
uiStartup--1242998156811212981416
load--1042830136110311011194
domContentLoaded--1036825134710310931190
domInteractive--2415105192084
firstPaint--177601102171181344
backgroundConnect--20118227313205223
firstReactRender--17105371928
getState--341582114057
initialActions--104113
loadScripts--84363711171029041000
setupStore--1353861424
numNetworkReqs--191278181274
19--------
BrowserifyPower User Home0--------
1--------
2--------
3--------
4--------
5--------
6--------
7--------
8--------
9--------
10--------
11--------
12--------
13--------
14--------
15--------
16--------
17--------
18--------
uiStartup--348217448933167347536232
load--1175955167914112721435
domContentLoaded--1157942166713612571402
domInteractive--36182563430111
firstPaint--218791343199238492
backgroundConnect--996216364395320292680
firstReactRender--22165452431
getState--3311421939285375937
initialActions--104112
loadScripts--91972713921259971143
setupStore--21759112745
numNetworkReqs--944720531104168
19--------
WebpackStandard Home0--------
1--------
2--------
3--------
4--------
5--------
6--------
7--------
8--------
9--------
10--------
11--------
12--------
13--------
14--------
15--------
16--------
17--------
18--------
uiStartup--803655119793846981
load--65157792377673797
domContentLoaded--64657291877669793
domInteractive--251688182280
firstPaint--1046132248128189
backgroundConnect--3151693437112
firstReactRender--15102731722
getState--321479154261
initialActions--102112
loadScripts--64457091676667791
setupStore--1164061222
numNetworkReqs--181283171266
19--------
WebpackPower User Home0--------
1--------
2--------
3--------
4--------
5--------
6--------
7--------
8--------
9--------
10--------
11--------
12--------
13--------
14--------
15--------
16--------
17--------
18--------
uiStartup--1293935260422013811687
load--69660794773699862
domContentLoaded--68460194373688856
domInteractive--38182083037117
firstPaint--1467138570192299
backgroundConnect--3585857821228
firstReactRender--22173232428
getState--15213133228153193
initialActions--102011
loadScripts--68259893472686848
setupStore--21752102345
numNetworkReqs--964824226105148
19--------
FirefoxBrowserifyStandard Home0--------
1--------
2--------
3--------
4--------
5--------
6--------
7--------
8--------
9--------
10--------
11--------
12--------
13--------
14--------
15--------
16--------
17--------
18--------
uiStartup--14331063200819915631802
load--1139917152712712091386
domContentLoaded--1138917152612712091386
domInteractive--743119944101162
firstPaint--------
backgroundConnect--57202884962169
firstReactRender--14105171436
getState--1162841122
initialActions--103122
loadScripts--1103902140311111611315
setupStore--165505501137
numNetworkReqs--191078171471
19--------
BrowserifyPower User Home0--------
1--------
2--------
3--------
4--------
5--------
6--------
7--------
8--------
9--------
10--------
11--------
12--------
13--------
14--------
15--------
16--------
17--------
18--------
uiStartup--25431855415439227163448
load--12371010216419413171604
domContentLoaded--12361010216419413171603
domInteractive--1505348598194342
firstPaint--------
backgroundConnect--3663314203356061033
firstReactRender--22155672331
getState--21267913159244586
initialActions--213122
loadScripts--1195988212918712541570
setupStore--13020626127158404
numNetworkReqs--83371452195127
19--------
WebpackStandard Home0--------
1--------
2--------
3--------
4--------
5--------
6--------
7--------
8--------
9--------
10--------
11--------
12--------
13--------
14--------
15--------
16--------
17--------
18--------
uiStartup--16181247212917217091926
load--13481109161210814181566
domContentLoaded--13481109161110814181566
domInteractive--962823447130166
firstPaint--------
backgroundConnect--58202443966144
firstReactRender--15122521519
getState--2272893515112
initialActions--2037422
loadScripts--1314109315619813701517
setupStore--164234261250
numNetworkReqs--191081161462
19--------
WebpackPower User Home0--------
1--------
2--------
3--------
4--------
5--------
6--------
7--------
8--------
9--------
10--------
11--------
12--------
13--------
14--------
15--------
16--------
17--------
18--------
uiStartup--29392103682682531044488
load--15931197523164815942693
domContentLoaded--15931197523164815942692
domInteractive--187441409211219469
firstPaint--------
backgroundConnect--4154828074246861070
firstReactRender--23165772534
getState--22764814177297661
initialActions--213123
loadScripts--15561176516964515652608
setupStore--11917676127136412
numNetworkReqs--81312653483163
19--------
📊 Page Load Benchmark Results

Current Commit: d7f9f88 | Date: 1/22/2026

📄 Localhost MetaMask Test Dapp

Samples: 100

Summary

  • pageLoadTime-> current mean value: 1.06s (±43ms) 🟡 | historical mean value: 1.03s ⬆️ (historical data)
  • domContentLoaded-> current mean value: 736ms (±41ms) 🟢 | historical mean value: 719ms ⬆️ (historical data)
  • firstContentfulPaint-> current mean value: 79ms (±11ms) 🟢 | historical mean value: 79ms ⬆️ (historical data)

📈 Detailed Results

Metric Mean Std Dev Min Max P95 P99
pageLoadTime 1.06s 43ms 1.02s 1.36s 1.08s 1.36s
domContentLoaded 736ms 41ms 706ms 1.03s 756ms 1.03s
firstPaint 79ms 11ms 60ms 172ms 88ms 172ms
firstContentfulPaint 79ms 11ms 60ms 172ms 88ms 172ms
largestContentfulPaint 0ms 0ms 0ms 0ms 0ms 0ms

@Gudahtt Gudahtt marked this pull request as ready for review January 22, 2026 16:46
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Copy link
Contributor

@davidmurdoch davidmurdoch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manually tested and can confirm that it fixes the issue.

@Gudahtt Gudahtt changed the title fix: Guard against invalid controller state fix: cp-13.14.2 Guard against invalid controller state Jan 22, 2026
@metamaskbotv2
Copy link
Contributor

metamaskbotv2 bot commented Jan 22, 2026

Builds ready [217ff83]
UI Startup Metrics (1275 ± 119 ms)
PlatformBuildTypePageMetricTest Title (ms)Persona (ms)Mean (ms)Min (ms)Max (ms)Std Dev (ms)P 75 (ms)P 95 (ms)
ChromeBrowserifyStandard Home0--------
1--------
2--------
3--------
4--------
5--------
6--------
7--------
8--------
9--------
10--------
11--------
12--------
13--------
14--------
15--------
16--------
17--------
18--------
uiStartup--12751029162411913401509
load--1072855137610911291295
domContentLoaded--1065852136810911231280
domInteractive--241595172173
firstPaint--144581016105175273
backgroundConnect--21419724910219233
firstReactRender--17103752027
getState--382178124464
initialActions--1010112
loadScripts--86065211551089191077
setupStore--1362941622
numNetworkReqs--181270141264
19--------
BrowserifyPower User Home0--------
1--------
2--------
3--------
4--------
5--------
6--------
7--------
8--------
9--------
10--------
11--------
12--------
13--------
14--------
15--------
16--------
17--------
18--------
uiStartup--251416226919108626605087
load--1051868160814411621317
domContentLoaded--1036860158414111501273
domInteractive--33161522629104
firstPaint--196631040139224368
backgroundConnect--48519427295535142133
firstReactRender--22154642331
getState--2691462023249229779
initialActions--103111
loadScripts--82767013411329111066
setupStore--1676181833
numNetworkReqs--80392073592165
19--------
WebpackStandard Home0--------
1--------
2--------
3--------
4--------
5--------
6--------
7--------
8--------
9--------
10--------
11--------
12--------
13--------
14--------
15--------
16--------
17--------
18--------
uiStartup--8386761182878751002
load--67659095068722821
domContentLoaded--67158693968715815
domInteractive--2716111192386
firstPaint--1196163783163279
backgroundConnect--216110222879
firstReactRender--18117681930
getState--3615142194565
initialActions--106113
loadScripts--66858493066713808
setupStore--1376681526
numNetworkReqs--181272161266
19--------
WebpackPower User Home0--------
1--------
2--------
3--------
4--------
5--------
6--------
7--------
8--------
9--------
10--------
11--------
12--------
13--------
14--------
15--------
16--------
17--------
18--------
uiStartup--1353944227226714491997
load--727616103289743929
domContentLoaded--715611101889729924
domInteractive--41171503040130
firstPaint--153711026109188293
backgroundConnect--51757311421499
firstReactRender--23174542429
getState--1545024825167203
initialActions--102011
loadScripts--712609100988727916
setupStore--19105192043
numNetworkReqs--1224029752154224
19--------
FirefoxBrowserifyStandard Home0--------
1--------
2--------
3--------
4--------
5--------
6--------
7--------
8--------
9--------
10--------
11--------
12--------
13--------
14--------
15--------
16--------
17--------
18--------
uiStartup--14701175220419615751872
load--1176931174212412451376
domContentLoaded--1176931174212412441376
domInteractive--853327549113151
firstPaint--------
backgroundConnect--66222185182195
firstReactRender--14104241419
getState--166252321333
initialActions--103122
loadScripts--1137917161911311951333
setupStore--1941292713107
numNetworkReqs--201081181571
19--------
BrowserifyPower User Home0--------
1--------
2--------
3--------
4--------
5--------
6--------
7--------
8--------
9--------
10--------
11--------
12--------
13--------
14--------
15--------
16--------
17--------
18--------
uiStartup--26041989616960028713732
load--12451024276627712731744
domContentLoaded--12441024276527712721743
domInteractive--159411273152169399
firstPaint--------
backgroundConnect--303321743356396982
firstReactRender--21155352329
getState--24349755175309600
initialActions--207123
loadScripts--1196997273926212231505
setupStore--14791364195158576
numNetworkReqs--71251352585117
19--------
WebpackStandard Home0--------
1--------
2--------
3--------
4--------
5--------
6--------
7--------
8--------
9--------
10--------
11--------
12--------
13--------
14--------
15--------
16--------
17--------
18--------
uiStartup--16371334236018917661980
load--13671135173312514541608
domContentLoaded--13661135173312614541608
domInteractive--952923145130163
firstPaint--------
backgroundConnect--62222584470163
firstReactRender--14112421520
getState--168235241622
initialActions--102122
loadScripts--13291116170811314061575
setupStore--2442584914141
numNetworkReqs--201080171573
19--------
WebpackPower User Home0--------
1--------
2--------
3--------
4--------
5--------
6--------
7--------
8--------
9--------
10--------
11--------
12--------
13--------
14--------
15--------
16--------
17--------
18--------
uiStartup--28802203746570630174211
load--15651258602154916052393
domContentLoaded--15641258602154916042393
domInteractive--1433549998170355
firstPaint--------
backgroundConnect--3034218183713911271
firstReactRender--23166062530
getState--28072883227401775
initialActions--208123
loadScripts--14941200593249815471803
setupStore--11618773144121433
numNetworkReqs--72351752786123
19--------
📊 Page Load Benchmark Results

Current Commit: 217ff83 | Date: 1/22/2026

📄 Localhost MetaMask Test Dapp

Samples: 100

Summary

  • pageLoadTime-> current mean value: 1.03s (±37ms) 🟡 | historical mean value: 1.04s ⬇️ (historical data)
  • domContentLoaded-> current mean value: 718ms (±35ms) 🟢 | historical mean value: 723ms ⬇️ (historical data)
  • firstContentfulPaint-> current mean value: 75ms (±11ms) 🟢 | historical mean value: 79ms ⬇️ (historical data)

📈 Detailed Results

Metric Mean Std Dev Min Max P95 P99
pageLoadTime 1.03s 37ms 1.00s 1.31s 1.05s 1.31s
domContentLoaded 718ms 35ms 688ms 985ms 737ms 985ms
firstPaint 75ms 11ms 56ms 168ms 84ms 168ms
firstContentfulPaint 75ms 11ms 56ms 168ms 84ms 168ms
largestContentfulPaint 0ms 0ms 0ms 0ms 0ms 0ms

@Gudahtt Gudahtt enabled auto-merge January 22, 2026 17:40
@Gudahtt Gudahtt added this pull request to the merge queue Jan 22, 2026
Gudahtt added a commit that referenced this pull request Jan 22, 2026
This PR updates the change log for 13.14.2. (Hotfix - no test plan
generated.)

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Updates release notes.
> 
> - Adds `13.14.2` section with a fix: prevent crash during
initialization when a controller has invalid state (#39465)
> - Updates `[Unreleased]` compare link to start from `v13.14.2` and
adds `[13.14.2]` compare reference
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
d8bca06. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Co-authored-by: metamaskbot <[email protected]>
Co-authored-by: Mark Stacey <[email protected]>
Merged via the queue into main with commit 3345f3e Jan 22, 2026
359 of 361 checks passed
@Gudahtt Gudahtt deleted the guard-against-invalid-controller-state branch January 22, 2026 18:33
@github-actions github-actions bot locked and limited conversation to collaborators Jan 22, 2026
@metamaskbot metamaskbot added the release-13.16.0 Issue or pull request that will be included in release 13.16.0 label Jan 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-13.16.0 Issue or pull request that will be included in release 13.16.0 size-XS team-core-platform Core Platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Sentry] TypeError: Cannot convert undefined or null to object

6 participants