我正在嘗試開發Chrome擴展程序,在按鈕單擊時打開一個新選項卡,然後在其中執行js。注入腳本時出錯
清單:
{
"author": "...",
"name": "...",
"manifest_version": 2,
"version": "1.0",
"description": "...",
"background": {},
"browser_action": {
"default_popup": "popup.html"
},
"permissions": [
"tabs","http://*/","https://*/"
]
}
popup.html:
<html>
<head>
<script src="jquery.min.js"></script>
</head>
<body>
<button type="button" id="saveBtn">Save</button>
<script type="text/javascript" src="popup.js"></script>
</body>
</html>
popup.js:
$("#saveBtn").click(function(){
chrome.tabs.create({
selected:false,
url:'https://analytics.google.com/something...'
},function(tab){
chrome.tabs.executeScript(tab.ib,{file:"jquery.min.js"});
chrome.tabs.executeScript(tab.ib,{file:"html2canvas.js"});
chrome.tabs.executeScript(tab.ib,{file:"FileSaver.js"});
chrome.tabs.executeScript(tab.id,{file:'inject.js'});
});
});
所有的JavaScript FIL es在同一個文件夾中。我收到此錯誤
在哪裏,我試圖注入jquery.min.js,html2canvas.js和FileSaver.js但不inject.js線Unchecked runtime.lastError while running tabs.executeScript: Cannot access a chrome:// URL at Object.callback (chrome-extension://jamfjopkccgnbpkhafanifhjambepphc/popup.js:8:23)
!新標籤打開正確,回調被執行,但然後錯誤被拋出。我在這裏做錯了什麼?
我們很清楚,您的網址是正確的,而不是'https://analytics.google.com/something ...'?因爲它看起來像你試圖擊中一個'chrome://'URL:你不能這樣做。 – Pogrindis
另外我必須引用你到這裏:http://stackoverflow.com/questions/24600495/chrome-tabs-executescript-cannot-access-a-chrome-url – Pogrindis