chrome.runtime.reload阻止扩展 [英] chrome.runtime.reload blocking the extension

查看:163
本文介绍了chrome.runtime.reload阻止扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我正在为webpack开发一个插件,用于热重载chrome扩展。
最大的问题是,如果我调用chrome.runtime.reload()这个特定次数,Chrome会阻止扩展:

 这个扩展重载本身的频率过高。 

事情是,我扼杀了重新加载了很多(如每5秒最多1次呼叫),这仍然发生。我在文档上搜索了很多。但没有发现与此相关的任何内容,所以我有点在黑暗中。



所以确实有一个门槛,或者您只能调用运行时重新加载阻止扩展之前固定次数?

更新:
为了解决这个问题,我已经为Chromium团队请求了一个新功能,
禁用快速重新加载功能,以阻止未分组的扩展程序。如果任何人有同样的问题,请给这个功能请求明星:)

解决方案

当达到阈值时(即快速连续重新加载5次),您必须等待至少10秒钟,然后才能重新安装计数器,并且可以安全地重新加载扩展。

来源 a>(修饰代码来强调相关逻辑):

  std :: pair< base: :TimeTicks,int>& reload_info = 
last_reload_time_ [extension_id];
base :: TimeTicks now = base :: TimeTicks :: Now();
if(reload_info.first.is_null()||
(now --reload_info.first).InMilliseconds()> kFastReloadTime){
reload_info.second = 0;
} else {
reload_info.second ++;
}

// ....

reload_info.first = now;
ExtensionService * service =
ExtensionSystem :: Get(browser_context _) - > extension_service();
if(reload_info.second> = kFastReloadCount){
// ....
base :: ThreadTaskRunnerHandle :: Get() - > PostTask(
FROM_HERE,base :: BindOnce(& ExtensionService :: TerminateExtension,
service-> AsWeakPtr(),extension_id));
extensions :: WarningSet警告;
warnings.insert(
extensions :: Warning :: CreateReloadTooFrequentWarning(
extension_id));

使用 kFastReloadTime kFastReloadCount defined 在这里


$ b

  //如果一个扩展重新加载在重新加载$ ​​b $ b //本身的许多毫秒内,重新加载被认为是快速的。 
const int kFastReloadTime = 10000;
//在很多可疑的快速连续重新加载之后,扩展将获得
//禁用。
const int kFastReloadCount = 5;


So, I'm developing a plugin for webpack for hot-reloading the chrome extensions. The biggest problem is, if I call a certain number of times the "chrome.runtime.reload()" this will make Chrome block the extension:

This extension reloaded itself too frequently.

On a old discussion they said that if you call the reload more than 5 times in a 10 seconds time frame, your extension will be blocked. The thing is, I've throttled the reloading a lot (like max 1 call each 5 seconds) and this still happening. I've searched a lot on the docs. but didn't found anything related to this, so I'm kind of in the dark.

So there's really a threshold for this or you only can call the runtime reload a fixed number of times before it blocks the extension?

UPDATE: To deal with this problem, I've requested a new feature for the Chromium team, Let disable the "Fast Reload" blocking for unpacked extensions. If anyone have the same problems, please give a star on this feature request :)

解决方案

When the threshold has been reached (i.e. reloaded 5 times in quick succession), you have to wait at least 10 seconds before the counter resets and the extension can safely be reloaded.

Source (trimmed code to emphasize the relevant logic):

  std::pair<base::TimeTicks, int>& reload_info =
      last_reload_time_[extension_id];
  base::TimeTicks now = base::TimeTicks::Now();
  if (reload_info.first.is_null() ||
      (now - reload_info.first).InMilliseconds() > kFastReloadTime) {
    reload_info.second = 0;
  } else {
    reload_info.second++;
  }

  // ....

  reload_info.first = now;
  ExtensionService* service =
      ExtensionSystem::Get(browser_context_)->extension_service();
  if (reload_info.second >= kFastReloadCount) {
    // ....
    base::ThreadTaskRunnerHandle::Get()->PostTask(
        FROM_HERE, base::BindOnce(&ExtensionService::TerminateExtension,
                                  service->AsWeakPtr(), extension_id));
    extensions::WarningSet warnings;
    warnings.insert(
        extensions::Warning::CreateReloadTooFrequentWarning(
            extension_id));

With kFastReloadTime and kFastReloadCount defined here:

// If an extension reloads itself within this many miliseconds of reloading
// itself, the reload is considered suspiciously fast.
const int kFastReloadTime = 10000;
// After this many suspiciously fast consecutive reloads, an extension will get
// disabled.
const int kFastReloadCount = 5;

这篇关于chrome.runtime.reload阻止扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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