fancy
fancy

Reputation: 51453

How can I inspect the window object for mobile safari?

How can I inspect the window object for mobile safari?

Or more specifically window.navigator - trying to convert to string doesn't work and I can't explore it within the console either.

Thanks!

EDIT:

console.log(window.navigator);

console.log(String(window.navigator));

console.log(JSON.stringify(window.navigator));

console.log(window.navigator.serialize());

Also tried sending all these variations over the socket to the server and logging them there.

Output is either [object Navigator], "{}", or nothing

Upvotes: 13

Views: 22221

Answers (5)

Mladen Janjetovic
Mladen Janjetovic

Reputation: 14664

You can also use this to activate Firebug on your device. Took me a lot of time to find this.

http://martinkool.com/post/13629963755/firebug-on-ipad-and-iphone

Upvotes: 1

Blaine
Blaine

Reputation: 1137

Update!!! On OS X you can use the Safari web inspector on the iOS Simulator AND iOS 6 devices.

  1. First enable the Developer menu in Safari.
  2. Next, enable remote debugging on your iOS device (or simulator).

    Settings > Safari > Advanced > Web Inspector (ON)
    
  3. Go back to Safari on your device.
  4. Go back to your computer, click the Developer menu, and select your device (e.g. iPhone Simulator, iPhone)

Note: You'll see your device in the Developer menu ONLY when Safari is active and running.

Enjoy!

Upvotes: 38

Marcel Korpel
Marcel Korpel

Reputation: 21763

Those outputs look entirely correct. E.g., when I ask for the string version of window.navigator, I correctly get

console.log(String(window.navigator));
"[object Navigator]"

On the other hand, when I ask for a specific value, I get (in Chromium):

console.log(window.navigator.userAgent);
"Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.71 Safari/534.24"

And when I try to enumerate all items, I get

for (var i in window.navigator) console.log(i);
language
product
mimeTypes
appVersion
plugins
onLine
platform
vendor
appCodeName
cookieEnabled
geolocation
appName
productSub
userAgent
vendorSub
javaEnabled
getStorageUpdates

(please be aware that in the above line of code I didn't check for hasOwnProperty, which you normally should use when iterating over object elements).

Upvotes: 1

Jonathan.
Jonathan.

Reputation: 55594

There isn't a Developer Tools window in mobile safari. There is a Debug Console, which will report errors in javascript, html and css, but it is nowhere near Developer Tools you'll find in a desktop browser. This debug console doesn't allow input of javascript (although this can be done in the address bar, eg javascript:alert("hi");)

To enable the Debug Console, open the settings app, go to the Safari menu, then Developer, and then turn on the debug console. Go back to Safari, scroll to the top of the page and it will be obvious what to do to get to the Debug Console.

Upvotes: 0

Teddy
Teddy

Reputation: 18572

I like jsconsole.com.

Also, you can use the json2.js library (https://github.com/douglascrockford/JSON-js), which will give you JSON.stringify() function.

console.log(JSON.stringify({a:'a',b:'b'});

Upvotes: 4

Related Questions