Copy Javascript Object from Safari Browser Console

Copy Javascript Object from Safari Browser Console

How to Share Console Logs from Safari as JSON

There are times when we need to test something specifically on Safari and share console logs with other developers. However, Safari often renders these logs as objects that can’t be copied directly as text JSON strings. I’ve found a workaround for this and wanted to share it.

Logging Objects in Safari

When you log an object in Safari, you might see something like this:

Right-clicking on the object gives you a few options. Choose “Log Value” to re-log the output in the console.

Getting the Variable Name

This does two things:

It prints a variable name, which appears just above the newly printed log.
It prints the actual object again.

If the variable name isn’t something like $1 or $2, try clicking “Log Value” again on the newly printed object. Now you should see a variable name with a $. – Note: You can also see the variable name at the end of the log like = $1 in grey color.

Copying the Object

Use the copy(<variable_name>) method to copy this object to the clipboard.

copy($1)

Note: Once the copy() command is executed, it will print undefined—this is just the return value of the copy() method.

Pasting the Copied Object

Now, open any text-editable input field or editor and paste the object you just copied.

And voilà! You’ve successfully copied and pasted your Safari console log as a JSON string.

Happy coding!