2013-10-07 21 views
2

我想運行chrome.tabs.executeScript來運行存儲在遠程服務器上的文件(出於測試目的,該服務器是本地主機)。這裏是我到目前爲止的代碼:chome.tabs.executeScript從外部文件?我需要在manifest.json中更改哪些權限?

chrome.tabs.executeScript(tabId, {file: 'http://localhost/js/myTestFile.js'}, function() { 
    //Do some stuff on completion 
}); 

我知道,在默認情況下,程序注入的內容腳本不能從遠程位置源,但可以通過「白名單」的清單某些來源改變這種狀況。這是我目前的清單:

//Extensions Permissions 
    "permissions": [ 
    "activeTab", 
    "notifications", 
    ], 

    //External access permissions 
    "externally_connectable": { 
    "matches": [ 
     "http://localhost/*", 
    ] 
    } 

    //Directories available to the extension 
    "web_accessible_resources": [ 
    "js/*", 
    "html/*", 
    "img/*" 
    ], 

    "content_scripts": [ 
    { 
     "matches": ["<all_urls>"], 
     "js": ["js/lib/require-2.1.8.min.js", "js/extension/contentManager.js"], 
     "all_frames": true 
    } 
    ], 

以什麼方式可以修改清單以允許將遠程JS文件作爲內容腳本注入?

回答

0

您需要詢問「選項卡」權限才能將腳本注入頁面。請注意,您可以向腳本注入代碼或鏈接。注入一個遠程腳本可能會有問題,但是您可以拉下JS並將其直接注入到頁面中。

要將遠程腳本包含到後臺頁面中,您需要列出content_security_policy中的域,並且除非它位於localhost上,否則它必須是https。