Code only works when placing a breakpoint

I got the following code (in a separate page.js file):

var page = new function() {

    this.getImdbID = function(){
        var imdbid = '';
        chrome.tabs.getSelected(null, function(tab) {
                 imdbid='0944835';
            }); 
            return imdbid;
    };
}

which is called by the following code (which is in background.html).

var imdbid = page.getImdbID();

This code only works when I put a breakpoint on "return imdbid;" row. When I skip a breakpoint, it returns only an empty string. Is there something I missed?

+3
source share
1 answer

The fact that it works when you set a breakpoint offers a synchronization problem.

, getSelected (, ), , .

+5

Source: https://habr.com/ru/post/1783492/


All Articles