为什么我的Google Chrome扩展程序无法在Google Chrome版本41.0.2272.89中使用

时间:2015-03-13 23:13:57

标签: javascript google-chrome plugins google-chrome-extension

我刚刚将两台计算机上的Google Chrome升级到版本41.0.2272.89,而我开发并在过去一年中在Google网上应用店中使用的Google Chrome扩展程序已不再适用。

这是我的清单文件:

{
  "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”按钮打开一个弹出窗口并立即关闭它。在使用OSX 10.7.5的mac上,弹出窗口保持打开状态,并且没有明显的错误。

在开发者模式下本地加载时测试了这些文件。

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

1 个答案:

答案 0 :(得分:1)

我只是在猜测,因为你没有说明理想的结果应该是什么。它是否打开一个窗口,上面写着“Maurice Wright的笔记和书签应用程序”,并有一个登录表单?

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

如果你拿出window.close(),我认为它会按你的意愿行事。顺便说一句,我正在使用Chrome 43的Windows 7计算机。