From fdd667e49e986bb7e01efffe7b23e0d211b5b05e Mon Sep 17 00:00:00 2001 From: Josh Kasten Date: Fri, 17 Nov 2023 22:53:18 +0000 Subject: [PATCH] throw error for sites using os.tc subdomain Effects any sites with the "My site is not fully HTTPS" option enabled. Before this change the initialization process would get too far and would result a confusing undefined error. Dead code will be cleaned up follow up commits. --- src/shared/utils/OneSignalUtils.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/shared/utils/OneSignalUtils.ts b/src/shared/utils/OneSignalUtils.ts index ad2316c17..8d20c6552 100644 --- a/src/shared/utils/OneSignalUtils.ts +++ b/src/shared/utils/OneSignalUtils.ts @@ -72,11 +72,26 @@ export class OneSignalUtils { } const windowEnv = SdkEnvironment.getWindowEnv(); - return ( + + const isHttp = location.protocol === 'http:'; + const useSubdomain = (windowEnv === WindowEnvironmentKind.Host || windowEnv === WindowEnvironmentKind.CustomIframe) && - (!!subdomain || location.protocol === 'http:') - ); + (!!subdomain || isHttp); + + if (useSubdomain) { + if (isHttp) { + throw new Error( + "OneSignalSDK: HTTP sites are no longer supported starting with version 16 (User Model), your public site must start with https://. Please visit the OneSignal dashboard's Settings > Web Configuration to find this option.", + ); + } else { + throw new Error( + 'OneSignalSDK: The "My site is not fully HTTPS" option is no longer supported starting with version 16 (User Model) of the OneSignal SDK. Please visit the OneSignal dashboard\'s Settings > Web Configuration to find this option.', + ); + } + } + + return false; } public static redetectBrowserUserAgent(): IBowser {