I'm building a chrome kiosk app in ReactJS that needs to access the deviceId of the device it is running on for logging purposes. I use the following code to call chrome.enterprise.deviceAttributes.getDirectoryDeviceId:
const getDeviceId = (cb) => {
if (!chrome.enterprise) {
if (cb) {
cb();
}
return;
}
// get device id
chrome.enterprise.deviceAttributes.getDirectoryDeviceId(assetId => {
deviceId = assetId;
if (cb) {
cb();
}
});
};
Afterwards, the function is called by doing something along these lines:
getDeviceId(() => {
debug('Got device id: %s', deviceId);
});
Now, I know that this code can only work on a enrolled, ChromeOS device. I also know that the chrome.enterprise.deviceAttributes is only available to extensions that are pre-installed by policy. Because of this I can only test it after it is submitted to the ChromeOS store and is installed via the developer dashboard.
Long story short: the above code doesn't return the deviceId and this causes all my api calls to fail, I can't really debug it because it gets installed as a kiosk app. I was wondering if anyone here could tell me what I'm doing wrong and how I can fix this.
Thanks in advance!
I'm building a chrome kiosk app in ReactJS that needs to access the deviceId of the device it is running on for logging purposes. I use the following code to call chrome.enterprise.deviceAttributes.getDirectoryDeviceId:
const getDeviceId = (cb) => {
if (!chrome.enterprise) {
if (cb) {
cb();
}
return;
}
// get device id
chrome.enterprise.deviceAttributes.getDirectoryDeviceId(assetId => {
deviceId = assetId;
if (cb) {
cb();
}
});
};
Afterwards, the function is called by doing something along these lines:
getDeviceId(() => {
debug('Got device id: %s', deviceId);
});
Now, I know that this code can only work on a enrolled, ChromeOS device. I also know that the chrome.enterprise.deviceAttributes is only available to extensions that are pre-installed by policy. Because of this I can only test it after it is submitted to the ChromeOS store and is installed via the developer dashboard.
Long story short: the above code doesn't return the deviceId and this causes all my api calls to fail, I can't really debug it because it gets installed as a kiosk app. I was wondering if anyone here could tell me what I'm doing wrong and how I can fix this.
Thanks in advance!
Share Improve this question asked Feb 8, 2017 at 15:35 sjaap2sjaap2 411 silver badge5 bronze badges 1- Try debugging by running chrome --whitelisted-extension-id=....... The API may get enabled. – woxxom Commented Feb 8, 2017 at 17:10
3 Answers
Reset to default 6I suspect you might not have the "enterprise.deviceAttributes" permission declared in your manifest.json:
"permissions": [
"enterprise.deviceAttributes"
],
That permission is listed in top section of the APIs page: https://developer.chrome./extensions/enterprise_deviceAttributes#intro
I am running this JavaScript inside of the content window I create in my Chrome App and it works well:
chrome.enterprise.deviceAttributes.getDirectoryDeviceId(deviceId => {
let publicDeviceId = document.getElementById('publicDeviceId');
publicDeviceId.innerText = deviceId;
});
It returns the value shown on Chrome Devices detail page in management console > Device Management > Chrome Devices > device detail page - section: Hardware and OS > Directory API ID. Its a GUID.
The API does work for Chrome Apps (which is the only place I've tested it) even though the documentation for the API redirects to the extensions page.
My problem was that I was using the code as a synchronous function while it is an asynchronous function. For the correct usage, look at Tom Dunn's answer on here.
Also make sure that your Chrome OS version is >= 66. I lost a few hairs because of this.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745091327a4610710.html
评论列表(0条)