为什么chrome.sockets.tcp.create()在应用程序后台脚本中不起作用? [英] Why chrome.sockets.tcp.create() does not work in app background script?
问题描述
我试图在应用程序的后台脚本中创建一个 tcp
套接字。
I am trying to create a tcp
socket in the background script of my app.
错误是( 1.js
中的第一行):
The error is (first line in 1.js
):
未捕获的TypeError:无法读取属性'tcp'未定义
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 file :
{
"manifest_version": 2,
"name": "UDP TEST",
"version": "1.0",
"app": {
"background": {
"scripts": ["1.js"]
}
},
"permissions": [
{
"socket": [
"tcp-listen:*:*",
"tcp-connect",
"resolve-host"
]
}
]
}
任何人都可以帮助我吗?谢谢!
Can anyone help me? Thanks!
推荐答案
您在清单中拥有错误的权限。查看Chrome API帮助:
https://developer.chrome.com/apps/sockets_tcp
(并且特定于清单: https://developer.chrome.com/ apps / manifest / sockets )
You have wrong permissions in manifest. Look up the Chrome API help: https://developer.chrome.com/apps/sockets_tcp (and specificaly for manifest: https://developer.chrome.com/apps/manifest/sockets)
权限应为sockets。您正在使用新的套接字API,但在您的清单中,您引用了旧的套接字权限( https ://developer.chrome.com/apps/socket )
The permissions should read "sockets". You are using the new "sockets" API, but in your manifest you are refering to old "socket" permissions (https://developer.chrome.com/apps/socket)
您的清单权限应为:
"permissions": [{
"sockets": {
"tcp": {
"connect": "127.0.0.1:4005"
}
}
}]
这篇关于为什么chrome.sockets.tcp.create()在应用程序后台脚本中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!