4

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!

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.com/forms/d/e/… and type this in: 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. Commented Jan 30, 2017 at 16:31

1 Answer 1

4

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)

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)

Your manifest permissions should read:

"permissions": [{
    "sockets": {
        "tcp": {
          "connect": "127.0.0.1:4005"
        }
    }
}]
Sign up to request clarification or add additional context in comments.

4 Comments

Did Google change its mind on this? It does not seem to work in 46 anymore. (According to this, sockets is not an option for permissions)
@Mario: It seems sockets only work in apps (for ChromeOS), not extensions.
@Zaz, Damn Chrome Team. How can we get this to work on extensions? chrome.sockets is undefined in both background.js and content.js.
@Pacerier: You can't use sockets in extensions. I don't think there's any way around this other than using an alternatives such as AJAX or WebSockets.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.