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]

相關問題