Problem
When initializing the @interopio/ng library using IOConnectNg.forRoot() directly in an @NgModule imports array e.g., in app.module.ts, intermittently get hard to pin down errors like:
"Cannot initiate glue, because this window was not opened or created by a glue client": this error occurs when the client app looks for a parent/opener window to send a “hello” message via thewindow.postMessageAPI and does not receive a response from the io.Connect Browser platform. There is a hardcoded 30-second timeout for this operation."IoConnect Browser has already been started for this application":this error occurs if there is a successful initialization and another one is started after that. It is thrown when the factory function is resolved andwindow.iobrowser.webStartedis alreadytrue.
Solution
The initialization pattern that uses IOConnectNg.forRoot() in an @NgModule imports array (typically in app.module.ts or main.module.ts) is intended for Angular 14 and earlier.
- For Angular 15 and later applications that use modules, use
importProvidersFrom()inapp.config.tsas in io.Connect Browser Documentation - Browser Client > Angular - Upgrade to the latest @interopio/ng (version 6) and Angular >= 19. Refer to the updated example of our tutorial apps repo for proper usage - browser-tutorials/angular/solution at G4E-9122-Update-Angular-tutorial · InteropIO/browser-tutorials under the ‘app’ folder in clients/stocks/client-details.
- An alternative approach is to initialize the
@interopio/browserJS SDK directly in your component’sngOnInit()method instead of using the@interopio/ngpackage. The@interopio/ngpackage is a thin wrapper on top of the JS SDK intended to let you work the “Angular way”, but it is not mandatory. This approach is used often, including with older Angular versions, and can be easier to maintain and wrap in client SDKs.
@interopio/ng Version Compatibility
See the compatibility matrix here - io.Connect Browser Documentation - Browser Client > Angular