0

我已成功在Chrome,Firefox和IE(全部为最新版本)上安装了我的crossrider扩展,但浏览器按钮(尽管全部启用)仅适用于Chrome。crossrider扩展安装在所有浏览器上,但只能在chrome中工作

后台代码似乎工作,因为我可以触发警报。

我background.js看起来是这样的:

appAPI.ready(function() { 
var popupDims = { 
    CH: {height: 400, width: 400}, 
    FF: {height: 400, width: 400}, 
    IE: {height: 400, width: 400}, 
    SF: {height: 400, width: 400} 
}; 

if ("CHFFIESF".indexOf(appAPI.platform) !== -1) { 
    appAPI.browserAction.setPopup({ 
     resourcePath:'popup.html', 
     height:popupDims[appAPI.platform].height, 
     width:popupDims[appAPI.platform].width 
    }); 
} 
else { 
    alert('This extension is not supported on your browser'); 
}}); 

在我popup.html我有一些javascript:

function crossriderMain($) { 
// load libraries 
eval(appAPI.resources.get('select2.js')); 

$('[as-trigger]').click(function() { 
    // retrieves the information for the active tab 
    appAPI.tabs.getActive(function(tabInfo) { 
     activeUrl = tabInfo.tabUrl; 

     appAPI.request.get({ 
      url: 'http://...', 
      onSuccess: function(response, additionalInfo) { 
       // show message 
      }, 
      onFailure: function(httpCode) { 
       console.log('GET:: Request failed. HTTP Code: ' + httpCode); 
      } 
     }); 


    }); 

}) 

$('[as-project-dropdown]').select2().on('select2-selecting', function (e) { 
    // some jquery code 
}); 

appAPI.request.get({ 
    url: 'http://...', 
    onSuccess: function(response, additionalInfo) { 
     var dataObject = JSON.parse(response); 

     $.each(dataObject.data, function(key, value) { 
      $('[as-project-list]').append('some html...'); 
     }); 

     $('[as-companyname]').html(dataObject.company); 
    }, 
    onFailure: function(httpCode) { 
     console.log('GET:: Request failed. HTTP Code: ' + httpCode); 
    } 
});} 

而且在我的Firefox的控制台,我可以通过我的分机看到抛出的错误:

MyExtension <Warning: document.getElementById(...) is null Function-name: appAPI.request.get User callback> 

@Crossrider支持:我的应用程序ID是65982

回答

1

看着你的代码,我可以看到你没有设置浏览器动作的图标。根据Browser Action docs,在某些浏览器上,这对按钮正确初始化至关重要。我用你的代码创建了一个扩展,并使用appAPI.browserAction.setResourceIcon添加了图标,按钮工作正常。

因此,采取的片段从background.js,添加图标如下:

appAPI.ready(function() { 
var popupDims = { 
    CH: {height: 400, width: 400}, 
    FF: {height: 400, width: 400}, 
    IE: {height: 400, width: 400}, 
    SF: {height: 400, width: 400} 
}; 

if ("CHFFIESF".indexOf(appAPI.platform) !== -1) { 
    appAPI.browserAction.setResourceIcon('logo.jpg'); 
    appAPI.browserAction.setPopup({ 
     resourcePath:'popup.html', 
     height:popupDims[appAPI.platform].height, 
     width:popupDims[appAPI.platform].width 
    }); 
} 
else { 
    alert('This extension is not supported on your browser'); 
}}); 

[披露:我是一个Crossrider empployee]

相关问题