gmusic-playlist.js icon indicating copy to clipboard operation
gmusic-playlist.js copied to clipboard

Error : unable to locate menu element

Open Glecun opened this issue 7 years ago • 3 comments

Hi,

I've got the message: "unable to locate menu element" in the console when I load the page with the script enabled.

I think the error is here: var menu = ui.search('//div[@class="nav-section-divider"]')[0]; He can't find it anymore for some reason... Maybe the HTML has been updated :/

So I replaced it with var menu = ui.search('//div[@id="music-content"]')[0];

Just for you know ;)

Glecun avatar Jun 29 '17 16:06 Glecun

thanks for the feedback.

seems like it still works for me on the old DOM path. i think google uses different UIs for different regions, so maybe that could be it.

there used to be ways I can trigger that error if I do things like interrupting the loading of the page before it's completely loaded in the dom for the menu. i can't seem to reproduce it right now though.

soulfx avatar Jun 30 '17 02:06 soulfx

Actually, I think we 've got the same DOM :)

I checked with jquery when the page was loaded and the <<//div[@class="nav-section-divider">> is here: image

I'm pretty sure that, with me, the page isn't fully loaded when the addui function is called. Because I tried to set a timeout and it worked perfectly this time :/

This code doesn't work:

var addui = function() {
    var ui = new XDoc(document);
    //var menu = ui.search('//div[@id="music-content"]')[0];
    var menu = ui.search('div[@class="nav-section-divider"]')[0];
    var inputui = ui.create('input',false,{'type':'file'});
    var importui = ui.create(
        'div',[ui.create('h4','Import Playlists'),inputui]);
    var exportlink = ui.create('a','Export Playlists',{'href':'#exportCSV'});
    var exportui = ui.create('div',ui.create('h4',exportlink));
    var statusout = ui.create('h6','ready');
    var statusui = ui.create('div',[statusout]);
    stat.element = statusout;
    var exporter = new Exporter();
    exporter.listenTo(exportlink);
    var importer = new Importer();
    importer.listenTo(inputui);
    if (menu) {
        menu.appendChild(importui);
        menu.appendChild(exportui);
        menu.appendChild(statusui);
    } else {
        console.log('unable to locate menu element');
    }
};
window.addEventListener ("load", addui, false);

But that dirty code works ;) :

var addui = function() {
    setTimeout(function(){
        var ui = new XDoc(document);
        var menu = ui.search('//div[@class="nav-section-divider"]')[0];
        var inputui = ui.create('input',false,{'type':'file'});
        var importui = ui.create(
            'div',[ui.create('h4','Import Playlists'),inputui]);
        var exportlink = ui.create('a','Export Playlists',{'href':'#exportCSV'});
        var exportui = ui.create('div',ui.create('h4',exportlink));
        var statusout = ui.create('h6','ready');
        var statusui = ui.create('div',[statusout]);
        stat.element = statusout;
        var exporter = new Exporter();
        exporter.listenTo(exportlink);
        var importer = new Importer();
        importer.listenTo(inputui);
        if (menu) {
            menu.appendChild(importui);
            menu.appendChild(exportui);
            menu.appendChild(statusui);
        } else {
            console.log('unable to locate menu element');
        }
    }, 3000);
};
window.addEventListener ("load", addui, false);

Strange isn't it ?

Glecun avatar Jun 30 '17 08:06 Glecun

@Glecun Thanks for providing that fix! You really saved my day.

aav7fl avatar Nov 26 '17 16:11 aav7fl