2012-09-02 85 views
0

可能重複:
Port error while changing chrome extension from manifest v1 to v2鉻附加組件在上下文菜單中沒有顯示

我想開發我的網站的插件。我的用戶將需要能夠在任何網頁右鍵點擊任何超鏈接,然後點擊,將帶他們到我的網站上執行操作的Chrome瀏覽器右鍵菜單中的鏈接。

我的插件已完成,但每次我嘗試測試它,鏈接不會出現在Chrome上下文菜單時,超鏈接是reght-點擊。

這裏是我的文件:

manifest.jason

{ 
"manifest_version": 2, 
"background_page": "background.html", 
"description": "Decrypt Short URLs.", 
"icons": { 
    "128": "icon-128.png", 
    "16": "icon-16.png", 
    "48": "icon-48.png" 
}, 
"minimum_chrome_version": "8.0.0.0", 
"name": "xxxx.xxx", 
"permissions": [ "http://*/*", "https://*/*", "tabs", "contextMenus" ], 
"version": "1.0" 
}  

background.html

<!DOCTYPE html> 

<html> 
<head> 

</head> 
<body> 
<script> 


    function handleClick() { 
    return function(info, tab) { 

     var url = 'http://xxx.xxx/api.php?url=' + info.linkUrl + '&source=chromeextension' 

     // Create a new tab to the results page 
     chrome.tabs.create({ url: url, selected:true }); 
    }; 
    }; 

    chrome.contextMenus.create({ 
    "title" : "Decrypt this Link", 
    "type" : "normal", 
    "contexts" : ["link"], 
    "onclick" : handleClick() 
    }); 
</script> 
</body> 

我會明白任何幫助。

+0

您應該在使用清單v。2時將腳本(函數handleClick()')提取到單獨的文件中。 – chaohuang

+0

也嘗試使用'function handleClick(info,tab)'而不是'function handleClick(){return函數(info,tab){}}' – chaohuang

+0

'chrome'的[document](http://developer.chrome.com/extensions/tabs.html#method-create)中找不到參數'selected:true' .tabs.create' – chaohuang

回答

1

我想這個問題是在你的清單文件。您可以使用清單版本2,但你的背景頁面被聲明爲在清單版本1

你應該嘗試改變manifest.json中的這一部分:在這一個

"background_page": "background.html", 

"background": { 
     "scripts": ["background.js"] 
    }, 

,並把所有的後臺代碼background.js

更多信息,你可以在這裏閱讀:background_pages

附:對不起,Mr. Rob W已經在主要問題的評論中指出了這個問題。

+0

謝謝Ceridan!是的,你和Rob W在這方面都是正確的。它解決了我的問題。 – Rian

相關問題