☁ Stormcloud


How to stop Safari 5.1 from unexpectedly reloading pages

Annoyed by Safari 5.1’s tendency to spontaneously reload pages when you didn’t ask it to? There’s a workaround for it, but it introduces a few problems of its own. Some Safari extensions will not work, and some of the new gestures won’t work either.

If you don’t rely on any extensions, and you can live without the new gestures (specifically, the new two-finger back/forward, smooth pinch-to-zoom, and the iOS-style smart-zoom), here’s how to fix it.

First, you need to enable the Debug menu in Safari, if you haven’t done so already. Copy the following line and paste it into a Terminal window, then quit and re-open Safari.

defaults write com.apple.Safari IncludeInternalDebugMenu 1

You should now see a Debug menu in Safari, to the right of the Help menu (not to be confused with the Develop menu). In this menu, disable “Use Multi-process Windows” by selecting it (when it’s disabled, it will no longer have a checkmark next to it).

Close all Safari windows. From this point, any new windows or tabs you create will have a title that ends in [SP] (“single process”). Safari will not reload any tabs in a single-process window. You can confirm this by selecting “Crash Web Process” from the Debug menu; this would normally trigger the tab-reloading behavior, but with “Use Multi-process Windows” disabled, this will no longer happen.

That’s it. If you end up missing your extensions or gestures, just re-enable “Use Multi-process Windows”.

If you use 1Password…

If you happen to use 1Password, you’ll notice it’s unable to automatically fill in your passwords in single-process windows. Fortunately, the 1Password pop-up (accessible via the [1P] toolbar button) still works, and still allows you to copy passwords and paste them yourself.

Some extensions will not work

Some extensions don’t work properly with single-process windows. In particular, extensions that interact with page content (such as ad and plugin blockers) don’t seem to work. If you find some of your extensions aren’t working properly, you might be able to install an older version of the extension that’s intended for Safari 5.0. I haven’t tried that, but if there are any extensions you can’t live without, it might be worth a shot.

Update: added info about missing gestures.

Update: I mistakenly referred to older versions of Safari extensions as being for Safari 4. Extensions were introduced in Safari 5, and it’s Safari 5.1 that moved to the new multi-process architecture of WebKit2 — i.e. this article actually only pertains to Safari 5.1. On further inspection, I’m not sure the reasoning I offered for extensions not working in single-process windows was accurate, so I’ve removed it.

Nerdy details (for those who care)

So what is a “multi-process window” anyway?

One of the new features in Safari 5.1 is a major new version of the underlying engine — WebKit2. Under WebKit2’s new process architecture, Safari consists of two separate processes — the “UI process” (the Safari application itself, including the address bar, toolbar, bookmarks bar, menus, etc.), and the “web process” (an independent process that loads and displays actual web pages).

Apart from other goals, the purpose of this is to provide some measure of crash protection. While it does prevent the entire Safari application from crashing (at least as far as I’ve seen), it doesn’t protect you from losing anything you’ve typed into text fields in web pages. All web content is handled by a single web process, so if any page malfunctions and causes the web process to crash, all open tabs will be reloaded, and anything you had typed into any of those pages will be lost. Furthermore, any downloads that were in progress will also be halted; you might be able to resume some downloads, but many will have to be started over. This can be very frustrating when downloading large files.

For that reason, the benefits of the new multi-process architecture are somewhat dubious, at least until Apple manages to address the issue of spontaneously reloading tabs (assuming it’s even possible to prevent this behavior without redesigning the overall architecture of WebKit again).

Check out the WebKit2 page on the official WebKit wiki for more details.