在google-chrome-extension中运行扩展

时间:2019-07-10 12:00:35

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

我正在尝试运行以下代码。 更多工具->扩展->加载解包-> chrome应用程序我在后台看到Clock Test页面(无效)。怎么运行呢?我没有看到任何弹出窗口。

index.html:

<!DOCTYPE html>
<html>
 <head>
  <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
  <script type="text/javascript" src="main.js" ></script>
 </head>
 <body>
  <span id="hhDisplay" ></span>:<span id="mmDisplay" ></span>
 </body>
</html>

main.js:

function updateClock() {
    var date = new Date();
    hhDisplay.innerHTML = date.getHours();
    mmDisplay.innerHTML = date.getMinutes();

    var minuteOffset = ((60 - date.getSeconds()) * 1000) - date.getMilliseconds();

    if (minuteOffset > 0)
            setTimeout(updateClock, minuteOffset);
    else
            updateClock();
}

window.onload = function() {
    chrome.idle.onStateChanged.addListener(function(newstate) { updateClock(); });
    updateClock();
}

background.js

chrome.app.runtime.onLaunched.addListener(function() {
    chrome.app.window.create("index.html",
    { id: "TestClock", minWidth: 400, minHeight: 300 }); 
});

manifest.json

{ "name": "Clock Test", "version": "1.0",
"manifest_version": 2,
"minimum_chrome_version": "18",
"app": { "background": {  "scripts": ["background.js"] } },
"permissions": ["idle"] }

0 个答案:

没有答案