2016-06-09 710 views
0

我需要絕對路徑來查看通過我的Chrome擴展下載的文件。 this通過使用chrome.downloads.DownloadItem.filename提到一個解決方案,但是當我嘗試使用這個,它給了我下面的錯誤。獲取Chrome擴展中下載文件的絕對路徑

uncaught_exception_handler:8 Error in event handler for downloads.onDeterminingFilename: TypeError: Cannot read property 'filename' of undefined at chrome-extension:/background.js:165:51handler @ uncaught_exception_handler:8(anonymous function) @ uncaught_exception_handler:100EventImpl.dispatch_ @ event_bindings:376dispatchArgs @ event_bindings:243massage_determining_filename @ downloads:54dispatchEvent @ extensions::event_bindings:250

是chrome.downloads.DownloadItem.filename仍然被支持或者我做錯了什麼?

更新:

**Permission in my manifest.json** 
"permissions": [ 
    "downloads", 
    "tabs" ] 

background.js:

chrome.downloads.download({url:"http://myserver.com/123.html"},function (id){ 
    console.log(chrome.downloads.id.filename); 
    LOG(id);}); 
+0

除了下載,我需要額外的許可嗎? – user3856170

+0

請給我們一些示例代碼,你可以調用這個函數 –

+1

也許你應該嘗試'chrome.downloads [id]'而不是'chrome.downloads.id'? – Zudwa

回答

1

文件名發生在以後的回調。尋找onProgress onChanged等輸入chrome.download。*回調,其中一個文件名將出現。

相關問題