bpolaszek/webpush-bundle

reference to webpush_client.js not reliable

Closed this issue · 1 comments

In webpush_client.js

var thisScript = document.getElementsByTagName('script')[document.getElementsByTagName('script').length - 1];

Should be replace by var thisScript = document.getElementById('pushClient'); with the pushClient ID added to your script tag in the template.

Because I work with OroCRM application which use requirejs and I can't guarantee that this script is the last one on the document.

Same problem with https://github.com/bpolaszek/bentools-pusher-bundle

Hi @AdriwanKenoby,

That's a good approach indeed. Instead of relying on an id (that might create an id collision), I would rather try on a data-attribute:

<script src="webpush_client.js" data-webpushclient></script>
// webpush_client.js
var thisScript = document.querySelector('script[data-webpushclient]');

What's your opinion?