0

Uncaught TypeError: Cannot read property 'config' of undefined

window.onload = function() {

var videoUrls = window.ytplayer.config.args.url_encoded_fmt_stream_map.split(',').map(function(item) {
    return  item.split("&").reduce(function(pre, cur){ 

        console.log(pre, cur); 
    });
});

    console.log("Our extension has loaded :)", videoUrls);
}

My problem is in the following code,

window.ytplayer.config.args.url_encoded_fmt_stream_map.split(',').map(function(item)
ibrahim mahrir
  • 31,174
  • 5
  • 48
  • 73
  • `window.ytplayer` is undefined - where do you think it is defined? – Bravo Nov 11 '19 at 12:29
  • That is probably because you're doing this in a content script which has a different context then the page that has the `window.ytplayer` property. Take a look at [Insert code into the page context using a content script](https://stackoverflow.com/questions/9515704/insert-code-into-the-page-context-using-a-content-script) – Titus Nov 11 '19 at 12:31

1 Answers1

0

window.ytplayer is not defined most probably. If that is defined too, then it does not contain config property on it. You can write it like this.

var videoUrls = window.ytplayer && 

    window.ytplayer.config.args.url_encoded_fmt_stream_map.split(',').map(function(item) {
        return  item.split("&").reduce(function(pre, cur){ 

            console.log(pre, cur); 
        });
    });