admin管理员组

文章数量:1395461

I am trying to create a tcp socket in the background script of my app.

The error is (first line in 1.js):

Uncaught TypeError: Cannot read property 'tcp' of undefined

Background script 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!

I am trying to create a tcp socket in the background script of my app.

The error is (first line in 1.js):

Uncaught TypeError: Cannot read property 'tcp' of undefined

Background script 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!

Share Improve this question asked Feb 8, 2015 at 10:52 KaBaKaBa 2853 silver badges16 bronze badges 2
  • Ok, we will need to spam the Chrome team so that they will know many people need Chrome Extensions to support UDP/TCP. GO to docs.google./forms/d/e/… and type this in: – Pacerier Commented Jan 30, 2017 at 16:31
  • .."We need chrome extensions to support UDP/TCP sockets. I can't migrate chrome.sockets to extensions dammit. Native messaging is not a real solution to chrome.sockets. Does it even make sense that I would have to create a Windows native app just to receive "UDP and TCP messages" from Chrome extension via Chrome's native message and then pass on those requests to the actual UDP and TCP? The performance hit is Huge (which would defeat the whole purpose of UDP and TCP in the first place)!" and hit submit suggestion. – Pacerier Commented Jan 30, 2017 at 16:31
Add a ment  | 

1 Answer 1

Reset to default 4

You have wrong permissions in manifest. Look up the Chrome API help: https://developer.chrome./apps/sockets_tcp (and specificaly for manifest: https://developer.chrome./apps/manifest/sockets)

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./apps/socket)

Your manifest permissions should read:

"permissions": [{
    "sockets": {
        "tcp": {
          "connect": "127.0.0.1:4005"
        }
    }
}]

本文标签: javascriptWhy chromesocketstcpcreate() does not work in app background scriptStack Overflow