Where does Safari store currently open windows

Where does Safari store open windows ? They reappear after a restart of the Mac or Safari or after a crash of Safari. I lost them somehow and hope I can reinstate them from my backup

I think it is in ~/Library/Containers/com.apple.Safari/Data/Library/Saved Application State/com.apple.Safari.savedState.

Update: This is wrong, see reply Where does Safari store currently open windows - #3 by mschmitt below

Note that this may appear in the Finder as ~/Library/Containers/Safari, due to what I consider to be a bug. I reported this to Apple.

1 Like

There’s more to it than this. Yesterday I accidentally closed Safari, so I restarted it to get back the window – I have Settings > General > Safari opens with: All windows from last session. The result was that it did reopen the window tabs, but it froze, and then crashed. And when I restarted Safari again, this time that tabs were all blank. It had lost the URLs for the tabs.

So, I quit Safari and replaced the Saved Application State folder from an older version. It didn’t work; it just opened a window but not with the last used web pages. Trying History options to reopen recently closed / last closed tab / all windows didn’t work either.

I also notice that when you quit Safari, the Saved Application State folder is deleted. So, which windows were used in the last session must be stored elsewhere.

I’m going to guess SafariTabs.db. I believe most, if not all, browsers switched to using databases for storing history long ago for performance reasons.

(trying it out…)

Yes, it works! I quit Safari, restored the three ~/Library/Containers/com.apple.Safari/Data/Library/Safari/SafariTabs.db* files from TimeMachine, and then when I restarted Safari my tabs were back.

3 Likes

@mschmitt You are describing a scenario that is almost identical to mine as far as the original event that took place is concerned. I’m going to replace the db files, but first, here’s something bizarre. How can there be three folders with identical names ā€˜Safari’? Looking with CMD+i their real names are

  1. com.apple.Passwords.MenuBarExtra
  2. com.apple.Passwords-Settings.extension
  3. com.apple.Safari

Only #3 contains the word ā€˜Safari’ in its name and the folder has the db files we’re after.

The Finder is lying to you. I first posted about this in July 2023: Finder changes display of Library > Containers.

You can see the true folder name if you drag one of the Safari’s to a Terminal window. On my machine there are two: com.apple.Safari and com.apple.Passwords-Settings.extension.

Rich Siegel (Bare Bones Software) told me ā€œThe illusory file name display for application containers in the Finder is a misfeature that was introduced in macOS 12ā€.

I reported this to Apple in May 2024. My feedback status is still Open, with no response from Apple. Maybe we need more people to report this as an issue.

For me this doesn’t work.

May only work if you have Safari set to re-open windows from the last session. But even if they don’t reopen automatically, since you’re restoring the history I’d think you could then use the History menu option to reopen all windows.

Safari was always set to ā€œre-open windows from the last sessionā€. The last session was already overwritten, I fear the history is my last resort.

Eventually I asked ChatGPT to analyse the Safari.db file for me. I’m not a coder, but gave so many prompts that it produced a csv file for me that rescued some 20 URLs for me. I expected about 40, but better half than nothing. The tool ChatGPT suggested first couldn’t open the file, but I was guided step by step through some terminal commands that did in the end give me something useable.