无法使用Chrome Power API [英] Unable to use Chrome Power API

查看:79
本文介绍了无法使用Chrome Power API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Chrome Power API来确保显示器保持活动状态.

I am trying to use the Chrome Power API to ensure the display stays active.

我尝试将以下代码行添加到我的background.js文件中,该文件失败了,并且还添加到了我的主应用程序js文件中,该文件也失败了

I have tried adding the following line of code to my background.js file, which failed, and also in my main app js file, which also failed

chrome.power.requestKeepAwake('display');

我究竟如何使用Power API(在GitHub示例中没有示例,也没有关于它的文档,除了上面的代码行,没有解释它应该去的地方,还是什么.

How exactly do I use the Power API (no exmaples in the GitHub samples, and no documentation about it, other then the above line of code, no explaination on where it should go, or anything.

编辑-这是我将其放在我的background.js中的方式,

EDIT - This is how I put it in my background.js, which didn't work

chrome.app.runtime.onLaunched.addListener(function() {
  chrome.power.requestKeepAwake('display');

  chrome.app.window.create('index.html', {
    'bounds': {
      'width': 1280,
      'height': 720
    }
  });
});

我知道

app.runtime.onLaunched事件处理程序中的错误:TypeError:无法读取未定义的属性"power"

Error in event handler for app.runtime.onLaunched: TypeError: Cannot read property 'power' of undefined

推荐答案

要使用"power" API,您需要声明适当的权限,如

To use the "power" API, you need to declare the proper permission, as indicated at the very beginning of documentation:

"permissions" : ["power"],

如果不包括此内容,则可能会遇到未定义"错误.

If you don't include this, you can run into the "undefined" error.

但是,您引用的错误是奇怪.应该是

However, the error you quote is strange. It should be

无法读取未定义的属性'requestKeepAwake'

Cannot read property 'requestKeepAwake' of undefined

再次检查错别字.我建议删除整个字符串并手动重新键入(可能会出现Unicode无法打印的杂散字符)

Double-check for typos. I recommend deleting the whole string and re-typing it by hand (a stray Unicode unprintable character is a possibility)

这篇关于无法使用Chrome Power API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆