bug(web): retrieving current script doesn't work when keymanweb script is injected
- Dominant language
- Pascal
- Stars
- 534
- Forks
- 143
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 113
Description
```
var scripts = document.getElementsByTagName('script');
var ss = scripts[scripts.length-1].src;
var sPath = ss.substr(0,ss.lastIndexOf('/')+1);
```
This is unreliable if the script is injected, for example:
```
var jsone = document.createElement("script");
jsone.addEventListener('load', function() {
keyman.init({
attachType: 'auto',
// root: 'https://s.keyman.com/kmw/engine/16.0.147/',
}).then(function() {
keyman.addKeyboards('@te');
// Loads Telugu keyboard from Keyman Cloud (CDN)
});
var jstwo = document.createElement("script");
jstwo.src = 'https://s.keyman.com/kmw/engine/16.0.147/kmwuitoggle.js';
document.head.appendChild(jstwo);
});
jsone.src = 'https://s.keyman.com/kmw/engine/16.0.147/keymanweb.js';
document.head.appendChild(jsone);
```
In the original reporter's situation, there are 14 script elements, and keymanweb.js is number 2, not number 13.
I think we should be able to use [`document.currentScript`](https://developer.mozilla.org/en-US/docs/Web/API/Document/currentScript) for this scenario?
Contributor guide
Assessment
This issue has not been assessed yet.