获取无法访问chrome:// URL,即使我没有调用它

时间:2017-01-20 07:54:08

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

背景

我只是想在Chrome扩展程序弹出窗口中运行列出的here列表中的google驱动器示例调用。以下是适用于常规html页面的实际原始代码的摘录:

有效的原始html:

  "browser_action": {
    "default_popup": "popup.html",
  },
  "background": {
    "scripts": ["background.js"],
    "persistent": false
  },
  "permissions": [
      "tabs","activeTab","https://apis.google.com/*"
  ],
  "content_security_policy": "script-src 'self' https://apis.google.com/*; 
                              object-src 'self'"

<小时/>

解释

我想将上面的内容转换为弹出窗口中显示的Chrome扩展程序..这就是我所拥有的内容(请参阅github repo处的完整代码):

的manifest.json

  ..
  <script src="popup.js"></script>
      ..
      <button id="authorize-button">
        Authorize
      </button>

popup.html

window.onload = function () {
    var otherWindows = chrome.extension.getBackgroundPage();
    chrome.tabs.executeScript(null, {file:"https://apis.google.com/js/client.js?onload=checkAuth"});
    var button = document.getElementById('authorize-button');
    button.onclick = function(event) {
        otherWindows.handleAuthClick(event);
    }
 }

popup.js

function handleAuthClick(event) {
  // gapi is defined in https://apis.google.com/js/client.js?
  gapi.auth.authorize(
   ...
}

background.js

Unchecked runtime.lastError while running tabs.executeScript: 
  Cannot access a chrome:// URL
    at chrome-extension://cmfbnommmmeccnkbochkfakncgnebckn/popup.js:3:17
    at chrome-extension://cmfbnommmmeccnkbochkfakncgnebckn/popup.js:5:3

<小时/>

问题

我收到此错误:

{{1}}

0 个答案:

没有答案