SDK-2871 Optimize Bundle Size by Using Simple UserAgent Parsing#1342
SDK-2871 Optimize Bundle Size by Using Simple UserAgent Parsing#1342fadi-george merged 12 commits intomainfrom
Conversation
f6603b1 to
8e4f09c
Compare
29eb2c7 to
2c2c9e8
Compare
2c2c9e8 to
b7667b0
Compare
sherwinski
left a comment
There was a problem hiding this comment.
FYI the following test is failing locally on this branch, it might be flaky:
src/onesignal/OneSignal.test.ts > OneSignal > Custom Events > custom event can execute before login for an existing user w/ no external id
Error: Timed out in waitUntil!
| (getBrowserName() === Browser.Chrome && | ||
| (isTabletBrowser() || isMobileBrowser())) || | ||
| requiresUserInteraction() |
There was a problem hiding this comment.
I'm not sure if this is still important today but we're missing this check:
Number(browserVersion) >= 63
| /* S T A T I C */ | ||
|
|
||
| /** | ||
| * Get the User Model Subscription type based on browser detection. | ||
| */ | ||
| public static getSubscriptionType(): SubscriptionTypeValue { | ||
| const browserName = getBrowserName(); | ||
| if (browserName === Browser.Firefox) { | ||
| return SubscriptionType.FirefoxPush; | ||
| } | ||
| if (useSafariVapidPush()) { | ||
| return SubscriptionType.SafariPush; | ||
| } | ||
| if (useSafariLegacyPush) { | ||
| return SubscriptionType.SafariLegacyPush; | ||
| } | ||
| // Other browsers, like Edge, are Chromium based so we consider them "Chrome". | ||
| return SubscriptionType.ChromePush; | ||
| } | ||
|
|
||
| /** | ||
| * Get the legacy player.device_type | ||
| * NOTE: Use getSubscriptionType() instead when possible. | ||
| */ | ||
| public static getDeviceType(): DeliveryPlatformKindValue { | ||
| switch (this.getSubscriptionType()) { | ||
| case SubscriptionType.FirefoxPush: | ||
| return DeliveryPlatformKind.Firefox; | ||
| case SubscriptionType.SafariLegacyPush: | ||
| return DeliveryPlatformKind.SafariLegacy; | ||
| case SubscriptionType.SafariPush: | ||
| return DeliveryPlatformKind.SafariVapid; | ||
| } | ||
| return DeliveryPlatformKind.ChromeLike; | ||
| } | ||
|
|
||
| public static getDeviceOS(): string | number { | ||
| const browserVersion = getBrowserVersion(); | ||
| return isNaN(browserVersion) ? -1 : browserVersion; | ||
| } | ||
|
|
||
| public static getDeviceModel(): string { | ||
| return navigator.platform; | ||
| } | ||
|
|
||
| public static getSdk(): string { | ||
| return String(VERSION); | ||
| } |
There was a problem hiding this comment.
nit: I'm a little confused why this logic is being moved to this file
There was a problem hiding this comment.
Not intended, removed
| export function isTabletBrowser(): boolean { | ||
| const ua = navigator.userAgent.toLowerCase(); | ||
|
|
||
| const isIPad = /\bipad\b/.test(ua); | ||
| const isAndroidTablet = /android/.test(ua) && !/mobile/.test(ua); // Android tablets don't include "mobile" | ||
| const isWindowsTablet = | ||
| /windows/.test(ua) && /touch/.test(ua) && !/phone/.test(ua); | ||
| const isKindleOrFire = /kindle|silk|kf[a-z]{2,}/.test(ua); // Amazon devices | ||
|
|
||
| return isIPad || isAndroidTablet || isWindowsTablet || isKindleOrFire; | ||
| } |
There was a problem hiding this comment.
Is there a resource we can link to that exhaustively lists the different user agents we can expect? It would be good for future reference.
There was a problem hiding this comment.
Ah I see there's one mentioned here: __test__/constants/useragent.ts. Might be good to add a comment in this file to either reference that same URL or this file.
There was a problem hiding this comment.
Added comment, logic was based off detect-ua package
| /** | ||
| * NOTE: This uses the OneSignal REST API POST /notifications with | ||
| * include_player_ids. This field will be dropped by 2025 so a | ||
| * replacement will needed by then. | ||
| */ |
There was a problem hiding this comment.
Is this still a concern? Something we might have to address in a future PR.
There was a problem hiding this comment.
I see a sendConvertedAPIRequests that reports a notification as clicked but I dont see post call anymore. This seems to be a misleading comment.
| if (useSafariVapidPush()) { | ||
| return SubscriptionType.SafariPush; | ||
| } | ||
| if (useSafariLegacyPush) { |
There was a problem hiding this comment.
Should this be useSafariLegacyPush()?
There was a problem hiding this comment.
I made it a basic constant. Also Ill remove these since they are in shared/environment
| @@ -0,0 +1,137 @@ | |||
| import Log from 'src/sw/libraries/Log'; | |||
There was a problem hiding this comment.
what's the difference between this Log and the one in src/shared/libraries/Log.ts?
There was a problem hiding this comment.
Should be src/shared/libraries/Log. In future prs ill combine them together
747f4a3 to
5463db9
Compare
- remove duplicate code - add version check for prompts manager
5463db9 to
b069192
Compare
Description
1 Line Summary
Details
Screenshots
iPad - Safari Desktop Browsing
iPad- Request Mobile Site
iPhone Safari:
macOS Safari:
Firefox:
Opera:
Edge:
Chrome:
Systems Affected
Validation
Tests
Info
Checklist
Programming Checklist
Interfaces:
Functions:
Typescript:
Other:
elem of arraysyntax. PreferforEachor usemapcontextif possible. Instead, we can pass it to function/constructor so that we don't callOneSignal.contextInfo
Checklist
Related Tickets
This change is