keymanapp / keyman

Keyman cross platform input methods system running on Android, iOS, Linux, macOS, Windows and mobile and desktop web
https://keyman.com/
Other
403 stars 112 forks source link

bug(web): retrieving current script doesn't work when keymanweb script is injected #11475

Open mcdurdin opened 6 months ago

mcdurdin commented 6 months ago
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 for this scenario?

ermshiperete commented 6 months ago

In the original reporter's situation, there are 14 script elements, and keymanweb.js is number 2, not number 13.

Do you have a link?

mcdurdin commented 5 months ago

In the original reporter's situation, there are 14 script elements, and keymanweb.js is number 2, not number 13.

Do you have a link?

Not a public one. Can send you one via slack.

ermshiperete commented 4 months ago

Moving this to the web bug fixes sprint since I didn't get to this in the assigned sprints. @mcdurdin