chrome.downloads.erase不起作用从内容脚本启动时 [英] chrome.downloads.erase not working When initiated from content script

查看:160
本文介绍了chrome.downloads.erase不起作用从内容脚本启动时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个Chrome扩展程序,以便在进入某个网站时使用。我正在删除下载历史记录。

  chrome.downloads.erase({},
function(item)
{
console.log(Erased item);
console.log(item);
});

问题在于,当我在输入邮件后从联系人脚本发送邮件时,它不起作用我想要的url。



我在内容脚本中使用send Message

  chrome.runtime.sendMessage 

并在后台页面接收消息

  chrome.runtime.onMessage.addListener 



 已擦除项目
Array

这是我得到的输出,虽然下载记录中有一些文件: [0]

如果我从后台页面控制台运行erase() p>

它似乎是因为没有用户交互而发生的。
如果我把一个清除按钮,并点击它删除确实有效
但是,如果我使用超时它不
任何想法,为什么发生?

我已经看到它与setTimeout
有关系,这可以在后台页面中使用:

  setTimeout(function(){
console.log('erasing downloads');
chrome.downloads.erase({});
}
,0);

但这并不是:

<$ p $ (){
console.log('erasing downloads');
chrome.downloads.erase({});
}
,1000);


解决方案

我想我终于找到了问题的原因。
下载之后,我用taskkill / f关闭了Chrome,如下所示:



taskKill / imchrome.exe/ f



重新打开Chrome之后,我在下载页面中找到了这一行:

thefilenamedownloaded.exe浏览器在下载完成前崩溃。



如果我使用taskKill / imchrome.exe(不带/ f),则问题不会发生。
这个错误实际上可能比这更复杂,因为当我进行用户交互时它也起作用。但现在它解决了我的问题。希望这可以帮助其他人

I am trying to create a Chrome extension that when entering a certain site. I am deleting the download history. I am using this from the background page:

chrome.downloads.erase({},
function(item)
{
    console.log("Erased item");
    console.log(item);
});

The problem is that it is not working when I am sending a message from the contact script after entering the url I wanted.

I use send Message in the content script

chrome.runtime.sendMessage

and receive the message in the background page

chrome.runtime.onMessage.addListener

This is the output I get although there are some files in the download history:

Erased item
Array[0]

If I run the erase() from within the background page console it works fine

it seems that it happens because there is no user interaction. If I put a clear button and click on it the deletion does works But if I use timeout it does not Any Idea why it happens?

I have seen that it has something to do with the setTimeout This works in the background page:

setTimeout(function(){
console.log('erasing downloads');
chrome.downloads.erase({});
}
, 0);

But this does not:

setTimeout(function(){
console.log('erasing downloads');
chrome.downloads.erase({});
}
, 1000);

解决方案

I think I had finally found the reason for the problem. After downloading I have closed Chrome with taskkill /f, like this:

taskKill /im "chrome.exe" /f

After reopening Chrome I got in this line in the download page:

thefilenamedownloaded.exe The browser crashed before the download completed.

If I used taskKill /im "chrome.exe" (without /f) than the problem did not happen. The bug may be actually more complicated than this because that when I had user interaction its also worked. But for now it solved my problem. Hopes this help anyone else

这篇关于chrome.downloads.erase不起作用从内容脚本启动时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆