为什么我的 Google Chrome 扩展在 Google Chrome 版本 41.0.2272.89 中不起作用

Why is my Google Chrome Extension not working in Google Chrome Version 41.0.2272.89

我刚刚在两台计算机上将 Google Chrome 升级到版本 41.0.2272.89,并且 Google Chrome 扩展是我在 Google 过去一年的网上商店不再有效。

这是我的清单文件:

{
  "manifest_version": 2,

  "name": "Maurice Wright - Note and Bookmarking App",
  "description": "Don't forget a thing! Easily save your most important notes and bookmarks. Use Mobile Safari's \"Add to Home Screen\" for iPads.",
  "version": "1.0",

  "permissions": [
    "tabs"
  ],
  "browser_action": {
    "default_icon": "ico_logo.png",
    "default_popup": "popup.html"
  },
  "icons" : {
    "48" : "ico_logo_48.png",
    "128" : "ico_logo_128.png"
  }
}

这是我的 popup.html 文件:

<!doctype html>
<html>
  <head>
    <title>Getting Started Extension's Popup</title>
    <style>
      body {
        min-width: 357px;
        overflow-x: hidden;
      }

      img {
        margin: 5px;
        border: 2px solid black;
        vertical-align: middle;
        width: 75px;
        height: 75px;
      }
    </style>

    <!--
      - JavaScript and HTML must be in separate files: see our Content Security
      - Policy documentation[1] for details and explanation.
      -
      - [1]: http://developer.chrome.com/extensions/contentSecurityPolicy.html
     -->
    <body></body>
    <script src="popup.js"></script>
  </head>
</html>

而且,这是我的 popup.js 文件:

var bookmarker = function() {

  var init = function() {
    chrome.tabs.getSelected(null, function(tab) {
        myFunction(tab.url,tab.title);
    });
  }

  var myFunction = function(tablink,tabtitle) {
    url = 'http://mwright.com/popup?title='+encodeURIComponent(tabtitle)+'&link='+encodeURIComponent(tablink);
    popup(url);
  }

  var popup = function(url) {
    var width  = 600;
    var height = 300;
    var left   = (screen.width  - width)/2;
    var top    = (screen.height - height)/2;
    var params = 'width='+width+', height='+height;
    params += ', top='+top+', left='+left;
    params += ', directories=no';
    params += ', location=no';
    params += ', menubar=no';
    params += ', resizable=no';
    params += ', scrollbars=no';
    params += ', status=no';
    params += ', toolbar=no';
    newwin = window.open(url,'windowname5', params);
    if ( window.focus ) { newwin.focus() }
    return false;
  }

  return {
    init :      init
  }

}();

document.addEventListener('DOMContentLoaded', function () {
  bookmarker.init();
});
window.close();

这在过去一年中一直有效。我不确定发生了什么变化,如何找出发生了什么变化,或者如何进行必要的更改以恢复扩展 -运行.

我已经在开发者模式下尝试 "Inspect Popup",但在控制台中没有看到任何错误。我应该提到,在使用 OSX 10.9.2 的 mac 上,"Inspect Popup" 按钮会打开一个弹出窗口 window 并立即将其关闭。在使用 OSX 10.7.5 的 mac 上,弹出窗口保持打开状态,没有明显的错误。

这些文件在开发人员模式下本地加载时进行了测试。

编辑: 保罗在下面提供了用于解决此问题的解决方案,并且是公认的答案。显然 Google Chrome 的最新版本对 window.close() 的处理方式不同。

我只是猜测,因为您没有指定期望的结果应该是什么。它会打开一个显示 "Maurice Wright's Note and Bookmarking App" 的 window 并有一个登录表单吗?

我相信您没有看到 window,因为在 popup.js 的底部有 window.close()。所以你的 window 在你意识到发生了什么之前打开和关闭。检查弹出窗口也是如此。那是因为 chrome 扩展 运行 在他们自己的范围内。这与检查选项卡并关闭该选项卡相同。您的检查员也将关闭。

如果你拿出window.close(),我想它会如你所愿。顺便说一句,我正在 Windows 7 机器上工作 Chrome 43。