Skip to content

Commit

Permalink
Removed unused bowser library use from shim
Browse files Browse the repository at this point in the history
* Shim before size 17.1KiB, now 8.4KiB! (before gzip)
* Moved redetectBrowserUserAgent implementation into OneSignalUtils.ts
  • Loading branch information
jkasten2 committed Sep 21, 2019
1 parent 1594caf commit 54f3657
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
19 changes: 1 addition & 18 deletions src/utils/BrowserSupportsPush.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,10 @@
// This is used by the OneSignalSDK.js shim
// DO NOT add other imports since it is an ES5 target and dead code imports can't be clean up.

import { IBowser } from "bowser";
import bowser from "bowser";

export function redetectBrowserUserAgent(): IBowser {
/*
TODO: Make this a little neater
During testing, the browser object may be initialized before the userAgent is injected
*/
let browser: IBowser;
if (bowser.name === '' && bowser.version === '') {
browser = bowser._detect(navigator.userAgent);
} else {
browser = bowser;
}
return browser;
}

// Checks if the browser supports push notifications by checking if specific
// classes and properties on them exist

// Safari -
// Safari
// macOS - typeof safari.pushNotification == "object"
// iOS - typeof safari == "undefined"
// Chrome
Expand Down
7 changes: 5 additions & 2 deletions src/utils/OneSignalUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import SdkEnvironment from "../managers/SdkEnvironment";
import { WindowEnvironmentKind } from "../models/WindowEnvironmentKind";
import Log from "../libraries/Log";
import { Utils } from "./Utils";
import { redetectBrowserUserAgent } from "./BrowserSupportsPush";

export class OneSignalUtils {
public static getBaseUrl() {
Expand Down Expand Up @@ -73,7 +72,11 @@ export class OneSignalUtils {
}

public static redetectBrowserUserAgent(): IBowser {
return redetectBrowserUserAgent();
// During testing, the browser object may be initialized before the userAgent is injected
if (bowser.name === '' && bowser.version === '') {
return bowser._detect(navigator.userAgent);
}
return bowser;
}

/**
Expand Down

0 comments on commit 54f3657

Please sign in to comment.