DEV Community

Cover image for Copy Javascript Object from Safari Browser Console
Dinesh D
Dinesh D

Posted on

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:

Safari Console Log

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

Safari Log Value Option

Getting the Variable Name

This does two things:

  1. It prints a variable name, which appears just above the newly printed log.
  2. 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.

Variable Name in Safari Console

Copying the Object

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



copy($1)


Enter fullscreen mode Exit fullscreen mode

Copy Command in Safari Console

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.

Pasting the Copied Object

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

Happy coding!

Top comments (0)