- browser.tabs.query({active:true, currentWindow:true})
- .then(
- function(tabs) {
- browser.tabs.executeScript(tabs[0].id, {file: '/icedeb-content.js'})
- .then(
- function(){
- browser.tabs.sendMessage( tabs[0].id, {url:url} );
- },
- function(err){
- console.log('Error executing script', err);
- });
-
- },
- function(err) {
- console.log('Error querying the active tab of the current window', err);
- open_tab(url);
- }
- );
+ //console.log('querying active tab');
+ return new Promise((resolve, reject) => {
+ browser.tabs.query({active:true, currentWindow:true})
+ .then(
+ function(tabs) {
+ //console.log('active tab queried');
+ browser.tabs.executeScript(tabs[0].id, {file: '/icedeb-content.js'})
+ .then(
+ function(){
+ //console.log('content script executed');
+ browser.tabs.sendMessage( tabs[0].id, {url:url} )
+ .then(
+ function() {
+ //console.log('message sent');
+ resolve();
+ },
+ function(err) {
+ console.log('error sending message', err);
+ reject(err);
+ }
+ );
+ },
+ function(err){
+ console.log('Error executing script. Probably a system tab is active', err, tabs[0]);
+ open_tab(url)
+ .then(
+ function() { resolve(); },
+ function(err) { reject(err); } );
+ });
+
+ },
+ function(err) {
+ console.log('Error querying the active tab of the current window', err);
+ open_tab(url)
+ .then(
+ function() { resolve(); },
+ function(err) { reject(err) }
+ );
+ }
+ );
+ });