bitwarden-estensione-browser/src/popup/main.ts

49 lines
1.5 KiB
TypeScript
Raw Normal View History

2018-04-04 04:14:54 +02:00
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
2018-04-11 16:57:34 +02:00
import 'web-animations-js';
2018-04-04 04:14:54 +02:00
// tslint:disable-next-line
2018-04-11 04:20:50 +02:00
require('./scss/popup.scss');
2018-04-04 04:14:54 +02:00
import { BrowserApi } from '../browser/browserApi';
2018-04-04 04:14:54 +02:00
import { AppModule } from './app.module';
2018-04-13 21:14:04 +02:00
if (process.env.ENV === 'production') {
enableProdMode();
}
2018-04-04 04:14:54 +02:00
function bootstrapModule() {
platformBrowserDynamic().bootstrapModule(AppModule, { preserveWhitespaces: true });
}
// Bug in Edge 18 has null getBackgroundPage() result initially. Can be removed in future.
if (BrowserApi.getBackgroundPage() == null && BrowserApi.isEdge18) {
const sleep = (time: number) => new Promise((resolve) => window.setTimeout(resolve, time));
const bootstrapForEdge18 = async () => {
let bgAttempts = 1;
while (BrowserApi.getBackgroundPage() == null) {
if (bgAttempts > 30) {
break;
}
// tslint:disable-next-line
console.log('Waiting for background page to not be null. Attempt #' + bgAttempts);
await sleep(200);
bgAttempts++;
}
if (BrowserApi.getBackgroundPage() == null) {
// tslint:disable-next-line
console.log('Reload page.');
window.location.reload();
} else {
bootstrapModule();
}
};
bootstrapForEdge18();
} else {
if (BrowserApi.isEdge18) {
// tslint:disable-next-line
console.log('Normal bootstrap.');
}
bootstrapModule();
}