Skip to content

Commit 1eba37b

Browse files
committed
Ensure that global.getSentryState is set in the background
1 parent dfba519 commit 1eba37b

File tree

3 files changed

+40
-23
lines changed

3 files changed

+40
-23
lines changed

app/scripts/background.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@ import {
2424
REJECT_NOTFICIATION_CLOSE_SIG,
2525
} from '../../shared/constants/metametrics';
2626
import { isManifestV3 } from '../../shared/modules/mv3.utils';
27+
import { maskObject } from '../../shared/modules/object.utils';
2728
import migrations from './migrations';
2829
import Migrator from './lib/migrator';
2930
import ExtensionPlatform from './platforms/extension';
3031
import LocalStore from './lib/local-store';
3132
import ReadOnlyNetworkStore from './lib/network-store';
33+
import { SENTRY_STATE } from './lib/setupSentry';
34+
3235
import createStreamSink from './lib/createStreamSink';
3336
import NotificationManager, {
3437
NOTIFICATION_MANAGER_EVENTS,
@@ -353,6 +356,8 @@ function setupController(initState, initLangCode, remoteSourcePort) {
353356
},
354357
);
355358

359+
setupSentryGetStateGlobal(controller.store);
360+
356361
/**
357362
* Assigns the given state to the versioned object (with metadata), and returns that.
358363
*
@@ -757,3 +762,15 @@ browser.runtime.onInstalled.addListener(({ reason }) => {
757762
platform.openExtensionInBrowser();
758763
}
759764
});
765+
766+
function setupSentryGetStateGlobal(store) {
767+
global.getSentryState = function () {
768+
const fullState = store.getState();
769+
const debugState = maskObject(fullState, SENTRY_STATE);
770+
return {
771+
browser: window.navigator.userAgent,
772+
store: debugState,
773+
version: global.platform.getVersion(),
774+
};
775+
};
776+
}

shared/modules/object.utils.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Return a "masked" copy of the given object.
3+
*
4+
* The returned object includes only the properties present in the mask. The
5+
* mask is an object that mirrors the structure of the given object, except
6+
* the only values are `true` or a sub-mask. `true` implies the property
7+
* should be included, and a sub-mask implies the property should be further
8+
* masked according to that sub-mask.
9+
*
10+
* @param {Object} object - The object to mask
11+
* @param {Object<Object|boolean>} mask - The mask to apply to the object
12+
*/
13+
export function maskObject(object, mask) {
14+
return Object.keys(object).reduce((state, key) => {
15+
if (mask[key] === true) {
16+
state[key] = object[key];
17+
} else if (mask[key]) {
18+
state[key] = maskObject(object[key], mask[key]);
19+
}
20+
return state;
21+
}, {});
22+
}

ui/index.js

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import browser from 'webextension-polyfill';
77

88
import { getEnvironmentType } from '../app/scripts/lib/util';
99
import { ALERT_TYPES } from '../shared/constants/alerts';
10+
import { maskObject } from '../shared/modules/object.utils';
1011
import { SENTRY_STATE } from '../app/scripts/lib/setupSentry';
1112
import { ENVIRONMENT_TYPE_POPUP } from '../shared/constants/app';
1213
import * as actions from './store/actions';
@@ -171,29 +172,6 @@ async function startApp(metamaskState, backgroundConnection, opts) {
171172
return store;
172173
}
173174

174-
/**
175-
* Return a "masked" copy of the given object.
176-
*
177-
* The returned object includes only the properties present in the mask. The
178-
* mask is an object that mirrors the structure of the given object, except
179-
* the only values are `true` or a sub-mask. `true` implies the property
180-
* should be included, and a sub-mask implies the property should be further
181-
* masked according to that sub-mask.
182-
*
183-
* @param {Object} object - The object to mask
184-
* @param {Object<Object|boolean>} mask - The mask to apply to the object
185-
*/
186-
function maskObject(object, mask) {
187-
return Object.keys(object).reduce((state, key) => {
188-
if (mask[key] === true) {
189-
state[key] = object[key];
190-
} else if (mask[key]) {
191-
state[key] = maskObject(object[key], mask[key]);
192-
}
193-
return state;
194-
}, {});
195-
}
196-
197175
function setupDebuggingHelpers(store) {
198176
window.getCleanAppState = async function () {
199177
const state = clone(store.getState());

0 commit comments

Comments
 (0)