【发布时间】:2019-10-08 12:05:11
【问题描述】:
背景
我有一个 Chrome Kiosk 应用程序,我想在其中使用 chrome.networking.onc API 让我的用户更改 WiFi 网络。
我的问题
在自助服务终端会话中运行时,无论是在应用后台脚本还是应用窗口中,应用都没有可用的 chrome.networking.onc API。
我尝试过的
根据chrome.networking.onc 文档,它应该在展台模式下可供应用使用。
我已将networking.onc 添加到我的应用清单中的permissions。
https://developer.chrome.com/apps/networking_onc
https://developer.chrome.com/apps/declare_permissions
使用 G Suite Chrome 设备管理策略将自助服务终端应用强制安装到用户的 Chromebook。
代码示例
app/manifest.json
{
"manifest_version": 2,
"name": "Kiosk networking.onc",
"version": "1.0",
"permissions": ["networking.onc"],
"kiosk_enabled": true,
"kiosk_only": true,
"app": {
"background": {
"scripts": ["background.js"]
}
}
}
app/background.js
chrome.app.runtime.onLaunched.addListener(function(launchData) {
// send a list of available chrome APIs to the app window to be displayed
chrome.app.window.create(`window/main.html?chrome=${Object.keys(chrome).join(",")}&kiosk=${launchData.isKioskSession}`);
});
app/window/main.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Chrome app</title>
</head>
<body>
<p>
<h1>Background <code>chrome</code> object properties</h1>
<div id="background"></div>
</p>
<p>
<h1>App window <code>chrome</code> object properties</h1>
<div id="window"></div>
</p>
<button id="exit">window.close()</button>
<script src="main.js"></script>
</body>
</html>
app/window/main.js
// display the available Chrome APIs in the background script
document.getElementById("background").innerText = window.location.search;
// display all the available Chrome APIs (accessible from the app window).
document.getElementById("window").innerText = Object.keys(chrome).join(",");
document.getElementById("exit").onclick = () => window.close()
在自助服务终端会话中输出 (Chrome OS 77.0.3865.105)
在下图中,在可用 API 中找不到 networking,如果我尝试访问 networking.onc,则会收到错误消息:Uncaught TypeError: Cannot read property 'onc' of undefined
【问题讨论】:
标签: chromium google-chrome-app google-chrome-os