cache bg page and more debug logs for edge 18
This commit is contained in:
parent
6c222f67b0
commit
f70f774bfb
|
@ -5,6 +5,8 @@ export class BrowserApi {
|
||||||
static isChromeApi: boolean = !BrowserApi.isSafariApi && (typeof chrome !== 'undefined');
|
static isChromeApi: boolean = !BrowserApi.isSafariApi && (typeof chrome !== 'undefined');
|
||||||
static isFirefoxOnAndroid: boolean = navigator.userAgent.indexOf('Firefox/') !== -1 &&
|
static isFirefoxOnAndroid: boolean = navigator.userAgent.indexOf('Firefox/') !== -1 &&
|
||||||
navigator.userAgent.indexOf('Android') !== -1;
|
navigator.userAgent.indexOf('Android') !== -1;
|
||||||
|
static isEdge18: boolean = navigator.userAgent.indexOf(' Edge/18.') !== -1;
|
||||||
|
static backgroundPageCache: any = null;
|
||||||
|
|
||||||
static async getTabFromCurrentWindowId(): Promise<any> {
|
static async getTabFromCurrentWindowId(): Promise<any> {
|
||||||
if (BrowserApi.isChromeApi) {
|
if (BrowserApi.isChromeApi) {
|
||||||
|
@ -133,7 +135,12 @@ export class BrowserApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
static getBackgroundPage(): any {
|
static getBackgroundPage(): any {
|
||||||
if (BrowserApi.isChromeApi) {
|
if (BrowserApi.isEdge18) {
|
||||||
|
if (BrowserApi.backgroundPageCache == null) {
|
||||||
|
BrowserApi.backgroundPageCache = browser.extension.getBackgroundPage();
|
||||||
|
}
|
||||||
|
return BrowserApi.backgroundPageCache;
|
||||||
|
} else if (BrowserApi.isChromeApi) {
|
||||||
return chrome.extension.getBackgroundPage();
|
return chrome.extension.getBackgroundPage();
|
||||||
} else if (BrowserApi.isSafariApi) {
|
} else if (BrowserApi.isSafariApi) {
|
||||||
return safari.extension.globalPage.contentWindow;
|
return safari.extension.globalPage.contentWindow;
|
||||||
|
|
|
@ -17,7 +17,7 @@ function bootstrapModule() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bug in Edge 18 has null getBackgroundPage() result initially. Can be removed in future.
|
// Bug in Edge 18 has null getBackgroundPage() result initially. Can be removed in future.
|
||||||
if (BrowserApi.getBackgroundPage() == null && window.navigator.userAgent.indexOf(' Edge/18.') !== -1) {
|
if (BrowserApi.getBackgroundPage() == null && BrowserApi.isEdge18) {
|
||||||
const sleep = (time: number) => new Promise((resolve) => window.setTimeout(resolve, time));
|
const sleep = (time: number) => new Promise((resolve) => window.setTimeout(resolve, time));
|
||||||
const bootstrapForEdge18 = async () => {
|
const bootstrapForEdge18 = async () => {
|
||||||
let bgAttempts = 1;
|
let bgAttempts = 1;
|
||||||
|
@ -40,5 +40,9 @@ if (BrowserApi.getBackgroundPage() == null && window.navigator.userAgent.indexOf
|
||||||
};
|
};
|
||||||
bootstrapForEdge18();
|
bootstrapForEdge18();
|
||||||
} else {
|
} else {
|
||||||
|
if (BrowserApi.isEdge18) {
|
||||||
|
// tslint:disable-next-line
|
||||||
|
console.log('Normal bootstrap.');
|
||||||
|
}
|
||||||
bootstrapModule();
|
bootstrapModule();
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,10 @@ export class LaunchGuardService implements CanActivate {
|
||||||
|
|
||||||
async canActivate() {
|
async canActivate() {
|
||||||
if (BrowserApi.getBackgroundPage() == null) {
|
if (BrowserApi.getBackgroundPage() == null) {
|
||||||
|
if (BrowserApi.isEdge18) {
|
||||||
|
// tslint:disable-next-line
|
||||||
|
console.log('getBackgroundPage is null from launch guard.');
|
||||||
|
}
|
||||||
this.router.navigate(['private-mode']);
|
this.router.navigate(['private-mode']);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue