Pierre
Pierre

Reputation: 35236

Firefox extension + TCP : "navigator is not defined"

I'm trying to build an extension for firefox inspired by http://mike.kaply.com/2011/01/18/writing-a-firefox-protocol-handler/

Firefox add-ons can add new schemes or protocols to the browser. This post will show you how to do that.

The deployement of this 'basic' extension is OK.

Now, I'd like to create a TCP connection as described in https://developer.mozilla.org/en-US/docs/Web/API/TCP_Socket_API

to get a mozTCPSocket (https://developer.mozilla.org/en-US/docs/Web/API/Navigator.mozTCPSocket) , an object navigator ( https://developer.mozilla.org/en-US/docs/Web/API/Navigator ) is needed.

But my extension says that navigator is undefined.

As far as I understand, I first need to find the window https://developer.mozilla.org/en-US/docs/Web/API/Window.navigator

how can I get this window.navigator.mozTCPSocket ? I'm looking for a solution that doesn't use the sdk.

Upvotes: 0

Views: 1076

Answers (1)

paa
paa

Reputation: 5054

You don't need access to the navigator object, and even in that case you would discover that currently mozTCPSocket is not enabled by default. Also notice that the TCP Socket API is marked as Firefox OS only.

The good news is you can create one directly.

var socket = Cc["@mozilla.org/tcp-socket;1"].createInstance(Ci.nsIDOMTCPSocket);

Upvotes: 1

Related Questions