chrome.runtime.reload blocking the extension

久未见 提交于 2019-12-12 18:04:57

问题


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 :)


回答1:


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;


来源:https://stackoverflow.com/questions/44522301/chrome-runtime-reload-blocking-the-extension

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