Accessing file data after download in Chrome…?

纵然是瞬间 提交于 2019-11-29 02:41:52

I struggled with the exact same problem and finally found an easy workaround to read the content of downloaded files from a Chrome extension.

You just need to add a permission to file://*in your manifest file and once you have your file's path in the system (with chrome.downloads.search in the filename property), make a GET XMLHttpRequest to the url file://{filepath}.

No, the Downloads API does not provide a way to access the file contents.

The closest for interception would be WebRequest API, but at the moment that doesn't allow response access either.

The most you can do is to catch a request with webRequest, cancel it and try to XHR it yourself, storing the result in some temporary place like the mentioned FileSystem API. This would be a terrible UX though (the original request fails inexplicably) and may not work in all cases (as XHR can't set all the headers to fully replicate a request).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!