2

I am attempting to use JS Navigator from a Python script, running pyv8.

The error I am being hit with is:

ReferenceError: navigator is not defined

I have tried the same code in JSFiddle and it works great, I can only assume running the JS from a browser allows access to more functions that the V8 engine allows.

Unfortunately my knowledge of JS (and pretty much anything web!) is very limited, i'm sure this is a trivial question for anyone with web experience, would someone kindly explain fundamentally why this happens, and how can I can go about avoiding it?

EDIT

Trying to get the outputs from this JSFiddle.

And so far my Python code is:

import PyV8

ctxt = PyV8.JSContext()
ctxt.enter()
ctxt.eval("navigator.geolocation.getCurrentPosition();")

I'm certain theres problems with that aswell (i.e actually showing the values), however right now i'm more concerned about why navigator is undefined.

Aphire
  • 1,621
  • 25
  • 55

1 Answers1

1

Off the bat I'd say that because you are not within a browser environment, there is no navigator global property available.

You'll need to find another way to get geolocation information... possibly using a Python library?

Alex
  • 4,844
  • 7
  • 44
  • 58
  • Unfortunately all the Python libraries I have used thus far have been pretty inaccurate (putting me in another country!),The JS method appeared to be the only accurate method that I have found. Do you know of any work-arounds for this? I will be glad to accept your answer as "answered" if no more answers that come closer appear within the next day – Aphire Jun 02 '15 at 09:26
  • You could potentially use the IP lookup services available, like MaxMind GeoIP2 which I believe has a free legacy service. Assuming you can get the user's IP address... obviously it's not 100% reliable because of networking security and so on, but I have used MaxMind (pay for service) and it's pretty accurate. – Alex Jun 02 '15 at 10:00
  • Thanks very much!, i'll take a look. – Aphire Jun 02 '15 at 10:07
  • Just tried the legacy version and unfortunately it is still placing my IP in wales (I live in england) Thanks for your help anyway, looks like I'm just gonna have to pay for better. Cheers – Aphire Jun 02 '15 at 11:38