google chrome extension - using promises in javascript -
var promise = new promise(function(resolve, reject) { //asynchronous part var dom_domain_name_encoded; chrome.tabs.query({ "active": true, "currentwindow": true, "status": "complete", "windowtype": "normal" }, function (tabs) { (tab in tabs) { dom_domain_name_encoded=tabs[tab].url; dom_domain_name_encoded = encodeuricomponent(dom_domain_name_encoded); console.log(dom_domain_name_encoded); // return dom_domain_name_encoded; } }); //asynchronous part ends here. if (dom_domain_name_encoded) { console.log("encoded , returning"); resolve(dom_domain_name_encoded); } else { console.log("error"); reject(error("it broke")); } }); promise.then( function(dom_domain_name_encoded) { console.log(dom_domain_name_encoded); } ).catch( function(reason) { console.log("promise not working"); } );
i created promise in chrome.tabs function getting executed. being asynchronous function put there. fetched url of current tab , passes .then method. in reference promises, expect run .then method going wrong , "error" getting in console.
am doing wrong?
Comments
Post a Comment