jos*_*r23 5 google-chrome-extension
我试图在 Chrome 扩展清单版本 3 中结束(并在进行一些分析后重新启动)文件下载之前停止。我使用 chrome.downloads.OnDeterminingFileName 和 chrome.downloads.OnCreated 事件来检测下载何时开始,然后是第一件事我的代码在该事件处理程序中使用 chrome.downloads.pause 方法来停止下载。添加:
chrome.downloads.onDeterminingFilename.addListener(function (downloadItem) {
if(downloadItem.fileSize < 20971520 && downloadItem.filename.endsWith('.exe') ){
chrome.downloads.pause(downloadItem.id);
console.log(downloadItem.id)
}
});
Run Code Online (Sandbox Code Playgroud)
问题是它无法处理小文件(小于 1MB),因为它正在下载。对于更大的,它工作得很好。我可以做些什么来解决这个问题吗?我可以避免这种行为吗?提前致谢。
我可以重现该问题,但没有解决方案。
chrome.downloads.onDeterminingFilename
If the listener calls suggest asynchronously, then it must return true.
The DownloadItem will not complete until all listeners have called suggest.
Run Code Online (Sandbox Code Playgroud)
因此,以下代码应自动暂停所有下载。
清单.json
If the listener calls suggest asynchronously, then it must return true.
The DownloadItem will not complete until all listeners have called suggest.
Run Code Online (Sandbox Code Playgroud)
背景.js
{
"manifest_version": 3,
"name": "Pause Downloads",
"version": "0.0.1",
"action": {
},
"background": {
"service_worker": "background.js"
},
"permissions": [
"downloads"
]
}
Run Code Online (Sandbox Code Playgroud)
我使用https://fastest.fish/test-files来测试不同文件大小的下载。
但正如您所说,该扩展仅暂停 >= 1 MB 的下载。
当我下载 1 KB 文件时,扩展程序会记录:
换句话说:扩展程序暂停下载,但 Chrome 会忽略这一点并完成下载。
如果其他人没有解决方案,您可能应该将其报告为错误,并链接到问题中的错误报告。
归档时间: |
|
查看次数: |
169 次 |
最近记录: |