From 72cb2772a6c2d2b867b379e634eefdae6ce81a43 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 27 Mar 2018 12:51:07 -0400 Subject: [PATCH] fix null refs when no background (ff private mode) --- src/popup/app/app.js | 17 ++++++++++------- src/popup/app/services/services.module.ts | 5 ++++- src/popup/app/services/state.service.ts | 6 ++++-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/popup/app/app.js b/src/popup/app/app.js index 9965cb5e0b..51f7ce21db 100644 --- a/src/popup/app/app.js +++ b/src/popup/app/app.js @@ -33,13 +33,16 @@ import { U2f } from '../../scripts/u2f'; window.U2f = U2f; import { Analytics } from '../../../jslib/src/misc/analytics'; -new Analytics(window, () => BrowserApi.gaFilter(), null, null, null, () => { - const bgPage = BrowserApi.getBackgroundPage(); - if (!bgPage || !bgPage.bitwardenMain) { - throw 'Cannot resolve background page main.'; - } - return bgPage.bitwardenMain; -}); + +if (BrowserApi.getBackgroundPage()) { + new Analytics(window, () => BrowserApi.gaFilter(), null, null, null, () => { + const bgPage = BrowserApi.getBackgroundPage(); + if (!bgPage || !bgPage.bitwardenMain) { + throw 'Cannot resolve background page main.'; + } + return bgPage.bitwardenMain; + }); +} // Model imports import { Attachment } from '../../../jslib/src/models/domain/attachment'; diff --git a/src/popup/app/services/services.module.ts b/src/popup/app/services/services.module.ts index 0330066425..698355b7be 100644 --- a/src/popup/app/services/services.module.ts +++ b/src/popup/app/services/services.module.ts @@ -13,7 +13,10 @@ const authService = new AuthService(backgroundServices.cryptoService(), backgrou backgroundServices.userService(), backgroundServices.tokenService(), backgroundServices.appIdService(), backgroundServices.i18n2Service(), backgroundServices.platformUtilsService(), backgroundServices.constantsService(), messagingService); -authService.init(); + +if (backgroundServices.i18n2Service()) { + authService.init(); +} export default angular .module('bit.services', ['toastr']) diff --git a/src/popup/app/services/state.service.ts b/src/popup/app/services/state.service.ts index c9a6d16a73..76baa2d5d4 100644 --- a/src/popup/app/services/state.service.ts +++ b/src/popup/app/services/state.service.ts @@ -9,8 +9,10 @@ export class StateService { } async init() { - const iconsDisabled = await this.storageService.get(this.constantsService.disableFaviconKey); - this.saveState('faviconEnabled', !iconsDisabled); + if (this.storageService != null) { + const iconsDisabled = await this.storageService.get(this.constantsService.disableFaviconKey); + this.saveState('faviconEnabled', !iconsDisabled); + } } saveState(key: string, data: any) {