OneSignal-Website-SDK icon indicating copy to clipboard operation
OneSignal-Website-SDK copied to clipboard

(Host) isUsingSubscriptionWorkaround() cannot be called until OneSignal.config exists

Open zhex900 opened this issue 2 years ago • 12 comments

Description:

I am tried to follow this guide to setup website push notification example.

On load I get this error

Uncaught (in promise) Error: (Host) isUsingSubscriptionWorkaround() cannot be called until OneSignal.config exists.

Steps to Reproduce Issue:

https://github.com/zhex900/push-msg

appId is correct. Try to run it.

yarn

yarn dev

zhex900 avatar Jun 10 '22 00:06 zhex900

Howdy, It looks like your project is set to private. Please update it so we can help you.

Cheers

rgomezp avatar Aug 12 '22 23:08 rgomezp

Is there any solution to this problem? I am having the same problem.

tcetin avatar Dec 16 '22 09:12 tcetin

Any update on this? i followed the documentations and it leads me to this error

HendryVarianto14 avatar Dec 21 '22 05:12 HendryVarianto14

@tcetin @HendryVarianto14 Can you try calling the function after you have called the async init function?

rgomezp avatar Jan 09 '23 22:01 rgomezp

Same error.

Next.js 12 Custom _document.ts with

import { Head, Html, Main, NextScript } from "next/document";

export default function Document() {
  return (
    <Html>
      <Head>
        <script async src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" />
      </Head>
      <body>
        <Main />
        <NextScript />
      </body>
    </Html>
  );
}

Added init to per-page layout (https://nextjs.org/docs/basic-features/layouts#per-page-layouts):

useEffect(() => {
    window.OneSignal = window.OneSignal || [];
    window.OneSignal.push(["init", {
      appId: "...",
      safari_web_id: "...",
      notifyButton: {
        enable: true,
      },
      allowLocalhostAsSecureOrigin: true,
    }]);

    return () => {
      window.OneSignal = undefined;
    };
  }, []);

Error:

OneSignalUtils.js:34 Uncaught (in promise) Error: (Host) isUsingSubscriptionWorkaround() cannot be called until OneSignal.config exists.

nehalist avatar Feb 04 '23 22:02 nehalist

https://github.com/zhex900/push-msg

@nehalist you resolved this error?

albertot-dev avatar Apr 13 '23 08:04 albertot-dev

https://github.com/zhex900/push-msg

@nehalist you resolved this error?

"Solved" isn't probably the right word, but adding OneSignalSDKUpdateWorker.js and OneSignalSDKWorker.js into my public directory solved some issues. HMR is still very bugged, which is probably the reason why I'll ultimately go with a different solution or wait until OneSignal releases a better SDK.

nehalist avatar Apr 14 '23 07:04 nehalist

I hit this same issue. Problem is that init is async, so you have to either await that or use .then before calling login.

bmulholland avatar Aug 18 '23 12:08 bmulholland

anyone solve this issue?

hishabee-nazu avatar Dec 10 '23 09:12 hishabee-nazu

@hishabee-nazu yes, see my comment above

bmulholland avatar Dec 10 '23 10:12 bmulholland

@hishabee-nazu yes, see my comment above

Thanks, man, It's working. I have just unexpectedly commented out my initial app calling

hishabee-nazu avatar Dec 12 '23 05:12 hishabee-nazu

I hit this same issue. Problem is that init is async, so you have to either await that or use .then before calling login.

tnx, man !)

SviatoslavMyhal avatar Dec 13 '23 12:12 SviatoslavMyhal