运行嵌入Google Chrome扩展程序

时间:2019-02-01 07:31:39

标签: javascript google-chrome-extension

//scripts.js

var div = document.getElementById('divID');

div.innerHTML += trends.embed.renderWidget("dailytrends", "", {"geo":"PL","guestPath":"https://trends.google.pl:443/trends/embed/"});
//manifest.json

{
    "name": "Chrome Extension Example",
    "version": "1.0",
    "description": "Build an Extension!",
    "manifest_version": 2,
    "page_action": {
        "default_popup": "newtab.html",
    },
    "content_scripts": [
        {
        "matches": ["https://*.gstatic.com/*", "https://*.trends.google.pl/*"],
        "js": ["scripts.js"],
        "run_at": "document_end"
        }
    ],
    "background": {
        "scripts": ["scripts.js"],
        "persistent": false
    },
    "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self' https://*.gstatic.com/*"
}
//newtab.html

<!doctype html>
<html>
  <head>
    <title>Trends</title>
    <style>
       
       body { 
            width: 500px;
            height: 600px;
       }
            
    </style>
  </head>
  <body>
    <h1>Trends</h1>
    
<div id="divID"> 
</div>

  </body>
</html>

我想在简单的 chrome扩展程序中运行此嵌入代码

<script type="text/javascript"> trends.embed.renderExploreWidget("TIMESERIES", {"comparisonItem":[{"keyword":"/m/0dl567","geo":"US","time":"now 7-d"},{"keyword":"/m/0261x8t","geo":"US","time":"now 7-d"}],"category":0,"property":""}, {"exploreQuery":"q=%2Fm%2F0dl567,%2Fm%2F0261x8t&date=now%207-d&geo=US","guestPath":"https://trends.google.pl:443/trends/embed/"}); </script> 
  

能否请您提示我如何执行此操作?我似乎无法   找出适当的清单,尝试过的背景,content_scripts,   content_security_policy,不知道如何正确使用哈希,我   不断收到控制台权限错误。

谢谢!

0 个答案:

没有答案