获取chrome扩展名中下载文件的绝对路径



我需要通过chrome扩展程序下载的文件的绝对路径。 这篇文章提到了使用 chrome.downloads.DownloadItem.文件名的解决方案,但是当我尝试使用 this 时,它给了我以下错误。

uncaught_exception_handler:8 下载的事件处理程序中出错。on确定文件名: 类型错误: 无法读取未定义的属性"文件名" at chrome-extension:/background.js:165:51handler @ uncaught_exception_handler:8(匿名函数) @ 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"  ]

背景.js:

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

文件名出现在后面的回调中。查找 onProgress onChanged 等类型 chrome.download.* 回调,其中一个将出现文件名。

最新更新