javascript – 为什么chrome.sockets.tcp.create()在app后台脚本中不起作用?
作者:互联网
我想在我的应用程序的后台脚本中创建一个tcp套接字.
错误是(1.js中的第一行):
Uncaught TypeError: Cannot read property ‘tcp’ of undefined
后台脚本1.js:
chrome.sockets.tcp.create({}, function(createInfo) {
chrome.sockets.tcp.connect(createInfo.socketId,
"127.0.0.1", 4005, function(socketInfo) {
});
});
清单文件:
{
"manifest_version": 2,
"name": "UDP TEST",
"version": "1.0",
"app": {
"background": {
"scripts": ["1.js"]
}
},
"permissions": [
{
"socket": [
"tcp-listen:*:*",
"tcp-connect",
"resolve-host"
]
}
]
}
谁能帮我?谢谢!
解决方法:
您在清单中拥有错误的权限.查看Chrome API帮助:
https://developer.chrome.com/apps/sockets_tcp
(并且明确表示:https://developer.chrome.com/apps/manifest/sockets)
权限应为“套接字”.您正在使用新的“套接字”API,但在您的清单中,您正在引用旧的“套接字”权限(https://developer.chrome.com/apps/socket)
您的清单权限应为:
"permissions": [{
"sockets": {
"tcp": {
"connect": "127.0.0.1:4005"
}
}
}]
标签:javascript,google-chrome,sockets,google-chrome-app 来源: https://codeday.me/bug/20190624/1275628.html