简体   繁体   English

xmlHttpRequest.send 使 Chrome 扩展程序崩溃

[英]xmlHttpRequest.send crashes Chrome Extension

I'm using a Chrome Extension to send a REST command to a simple API.我正在使用 Chrome 扩展程序将 REST 命令发送到一个简单的 API。

I have an icon that has a popup menu:我有一个带有弹出菜单的图标:

<body>
   <button id="Enable">Enable</button>
   <button id="Disable">Disable</button>
   <script src="popup.js"></script>
</body>

This is the code in popup.js这是 popup.js 中的代码

  Enable.onclick = function(element) 
  {
    var request = new XMLHttpRequest();
    request.open("GET", "http://192.168.100.110/admin/api.php?enable&auth=xxxx", false);
    request.setRequestHeader("Content-type", "application/json");
    request.send();
    var response = JSON.parse(xmlHttpRequest.responseText);
  };

The URL works fine when sent from the browser.从浏览器发送时,URL 工作正常。

When I open the Debugger using "Inspect PopUp" and click the Enable button in the popup menu the code crashes the extension at request.send();当我使用“Inspect PopUp”打开调试器并单击弹出菜单中的“启用”按钮时,代码在 request.send() 处使扩展程序崩溃;

The debugger also closes.调试器也会关闭。 I don't see any error messages.我没有看到任何错误消息。

Manifest:显现:

{
  "name": "Enable/Disable",
  "version": "1.0",
  "description": "Enables/Disables",

  "options_page": "options.html",
  "browser_action": 
  {
    "default_popup": "popup.html",
    "default_icon": 
    {
      "16": "images/Icon - 16x16.png"
    }
  }
 "manifest_version": 2
}

Any suggestions as to where I've gone wrong?关于我哪里出错的任何建议?

Most of the time chrome extensions crash because they run out of memory.大多数情况下,chrome 扩展会因为内存不足而崩溃。 Due to high memory usage chrome runs out of memory, therefore it stops the process(extension) as every process is an independent thread.由于内存使用率高,chrome 内存不足,因此它会停止进程(扩展),因为每个进程都是一个独立的线程。

You can check the memory usage of your extension(or any of your chrome tabs) by opening the Chrome task manager (Shift+Esc).您可以通过打开 Chrome 任务管理器 (Shift+Esc) 检查扩展程序(或任何 chrome 标签页)的内存使用情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM