CaliStyle / ng-intercom

Angular 7+ Wrapper for Intercom.com
MIT License
54 stars 46 forks source link

Intercom js loaded on window.onload instead of scriptElement.onload #58

Closed tiberiumihai closed 6 years ago

tiberiumihai commented 6 years ago

Versions

Description

IntercomJS is loaded on window.onload event instead of scriptElement.onload, or by a function to init and load the js.

When intercom js is injected before window.load is fired, the module will load and work just fine. But when intercom is injected after window.load was fired, the intercom JS won't be loaded because window.load already fired, and thus the component won't work.

To fix this issue, we had to use this workaround in our wrapper component to manually load the intercom js.

const intercomJsNotLoaded = !$(`script[src="https://widget.intercom.io/widget/${environment.intercomKey}"]`).length;
if (intercomJsNotLoaded) {
  // Load Intercom JS
  const loadIntercomJS: any = this.intercom.l(this.intercomConfig);
  loadIntercomJS.apply(this.intercom);
}

Possible solution

Is it possible to move the module loading through a function to be called manually or replace the window.onload with scriptElement.onload of the intercom js script injected?

tienvx commented 6 years ago

I confirm this is a bug. The workaround work like a charm.

wbhob commented 6 years ago

I'd definitely be open to seeing a PR for this issue. This seems like a simple enough fix, but currently the behavior lives inside the provider. I remember, it was formerly outside of the provider, and would execute before Angular's instantiation. I'd be open to seeing a new implementation of a fix for this issue, though. Thanks!

tiberiumihai commented 6 years ago

Sure. I'm working on a Fix, I'll send a PR when it's finished. Thanks!

tiberiumihai commented 6 years ago

I'm trying to push a new branch fix-injecting-intercom-script where the changes resides but I get this:

ERROR: Permission to CaliStyle/ng-intercom.git denied to tiberiumihai.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
scott-wyatt commented 6 years ago

You’ll want to fork the repo and do a pull request. Thanks!

Sent from out and about

On Aug 3, 2018, at 6:45 AM, tiberiumihai notifications@github.com wrote:

I'm trying to push a new branch fix-injecting-intercom-script where the changes resides but I get this:

ERROR: Permission to CaliStyle/ng-intercom.git denied to tiberiumihai. fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists. — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

tiberiumihai commented 6 years ago

@wbhob @scott-wyatt I've added the PR with the fix. Can you take a look and let me know if it requires anything else? It seems that the bug is gone after this fix.

tiberiumihai commented 6 years ago

After merging and publishing to 6.0.0beta3, this issue is now fixed. Thanks!

Closing.