chrome扩展访问非活动标签/清单必须请求权限

时间:2018-01-06 22:40:17

标签: google-chrome-extension permissions cross-domain

我想创建一个chrome扩展程序,它能够打开yelp页面的非活动选项卡,并从该页面获取一些内容(如标题)并在弹出窗口中显示这些内容。但Chrome控制台显示错误:

  

扩展程序清单必须请求权限。

manifest.json:



var tab_title = '';
var tab_id='';
function display_h1 (results){
  h1=results;
  document.querySelector("#id1").innerHTML = "<p>tab title: " + tab_title + "</p><p>dom h1: " + h1 + "</p><p>id:"+tab_id+"</p>";
}
chrome.tabs.create({url:'https://www.yelp.com/biz/bareburger-forest-hills?osq=burger', active:false});

chrome.tabs.query({active:false}, function(tabs) {
  var tab = tabs[tabs.length-1];
  tab_title = tab.title;
  tab_id=tab.id;
  chrome.tabs.executeScript(tab.id, {
    code: 'document.querySelectorAll("[itemprop=description]")[0].textContent'
  }, display_h1);
});
&#13;
{
  "name": "Hello World",
  "description": "Hello World Chrome App.",
  "version": "0.1",
  "manifest_version": 2,
  "permissions": [
    "tabs",
    "activeTab",
    "bookmarks",
        "http://*/",
        "https://*/",
        "*://www.yelp.com/fe",
        "https://www.yelp.com/biz/bareburger-forest-hills?osq=burger"
  ],
  "browser_action": {
    "default_icon": "hello-16.png",
    "default_popup": "popup.html"
  }
}
&#13;
<!DOCTYPE html>
<html style="min-width:300px;min-height:300px;">
  <head>
  </head>
  <body>
    <div id="id1">-</div>
    <script type="text/javascript" src="popup.js"></script>
  </body>
</html>
&#13;
&#13;
&#13;

0 个答案:

没有答案