【问题标题】:chrome extension download API is slow to respond and doesn't change the filenamechrome 扩展下载 API 响应缓慢且不更改文件名
【发布时间】:2017-09-11 16:28:58
【问题描述】:

我正在使用 chrome 消息传递功能发送文件名和链接到后台页面

  chrome.runtime.sendMessage({link: thelink, name:filename}, function(response) {});

背景.js

   chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
        console.log(message.name);
            chrome.downloads.download({
                                url: message.link,
                                filename: message.name,
                                conflictAction: 'prompt'
                            });

        });

我的 manifest.json

{
    "manifest_version": 2,
    "name": "4ch",
    "description": "This extension shows a Google Image search result for the current page",
    "version": "1.0",
    "icons": {
        "16": "4ch-icon-16.png", "48": "4ch-icon-48.png", "128": "4ch-icon-48.png"
    }
    ,
    "permissions": ["downloads",
    "<all_urls>",
    "contextMenus"],
    "content_scripts": [{

      "js": ["script/jquery.js", "script/reddit.js"],
       "matches": ["*://*.reddit.com/*"]  
    }


    ],
    "background": {
        "scripts": ["script/jquery.js","script/eventpage.js"], "persistent": false
    }
}

下载仅在几秒钟后开始,并且不会更改文件名

【问题讨论】:

  • 刚刚试了一下,对我来说效果很好。需要更多上下文。如果有延迟,它可能在您调用 sendMessage 或其他内容之前出现在您的内容脚本中。如果您检查后台页面,您是否在控制台中看到任何错误?
  • 它对你有用吗?我只是在后台页面控制台中尝试使用链接和文件名。而且文件没有我给的名字
  • 是的。在我的扩展程序的背景页面中运行它就可以了:chrome.downloads.download({ url: "http://thecatapi.com/?id=cco", filename: "g.png", conflictAction: 'prompt' }); 我还使用runtime 做了一个完整的测试,就像你的问题一样,这也很好。因此,我们需要有关您的上下文的更多信息。
  • 谢谢。我想到了。我的扩展程序与“chrome download Master”扩展程序冲突当我禁用它时它可以工作
  • edit 成为主题的问题:包括一个minimal reproducible example 重复问题。对于 Chrome 扩展程序或 Firefox WebExtensions,您几乎总是需要包含您的 manifest.json 和一些背景、内容和/或弹出脚本/HTML,通常是网页 HTML/脚本。寻求调试帮助的问题(“为什么我的代码没有按我想要的方式工作?”)必须包括:(1)期望的行为,(2)特定的问题或错误以及(3)重现它所需的最短代码在问题本身中。另请参阅:What topics can I ask about here?How to Ask

标签: google-chrome google-chrome-extension


【解决方案1】:

我找到了一个解决方案。 “下载大师”扩展名与我自己的冲突,因此它不会替换原始文件名。我已禁用它

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-17
    • 1970-01-01
    • 1970-01-01
    • 2012-12-31
    • 2019-11-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多