YouTube is a popular video sharing site, now owned by Google. As well as the website (and "YouTube channels") it also allows people to embed their uploaded videos into other pages so that they can play back in place. This all worked pretty well until a few weeks ago, when every attempt to play an embedded video resulted in a few HTTP requests and then the message "An error occurred, please try again later". Of course it didn't work later either; only going through to the YouTube site and playing the video there worked. It seems to be a fairly common problem, although interestingly mostly seeming to affect Mac users.

A number of fairly drastic solutions have been reported to fix the problem, such as "Tools -> Clear Recent History... -> Everything" but that has a number of undesirable side effects (not least of which is that it deletes all cookies and login sessions for every site). Others have suggested allowing all cookies for youtube.com, or that deleting your cookies once is enough.

On looking more closely at my setup, I noticed that I'd allowed cookies from "www.youtube.com" (for the session), but not for all "youtube.com" and subsites. This "allow cookies" combination seemed to work for me:

  1. Allow all "youtube.com" cookies (for the session) (Firefox -> Preferences -> Privacy -> Exceptions, enter "youtube.com" and click "Allow For Session", then delete other youtube.com entries such as "www.youtube.com" so that the top level one applies to all YouTube cookies)

  2. Remove all the existing (session) cookies (Firefox -> Preferences -> Privacy -> Show Cookies... highlight "youtube.com" and "Remove Cookies")

after which the embedded videos would play.

Curiously this "block cookies" combination also seems to work:

  1. Block all "youtube.com" cookies (for the session) (Firefox -> Preferences -> Privacy -> Exceptions, enter "youtube.com" and click "Allow For Session", then delete other youtube.com entries such as "www.youtube.com" so that the top level one applies to all YouTube cookies)

  2. Remove all the existing (session) cookies (Firefox -> Preferences -> Privacy -> Show Cookies... highlight "youtube.com" and "Remove Cookies")

and the embedded videos played then too. And since I prefer to reduce random tracking on the Internet I'm going to try that out for a while.

Having looked at the requests being made (see also detailed example of failure) my best guess is that the error is resulting from an inconsistent set of cookies being presented (due to some being allowed and others blocked) so that it thinks it has a valid session and then it turns out not to be valid. Removing all the YouTube cookies removes that potentially valid session, and allowing the cookies lets it establish a new one. Removing the YouTube cookies and blocking them stops it establishing a new session (and discards the invalid one), although it's likely that it then tries to use Flash Cookies for tracking instead. (It may well use Flash Cookies even if it is able to use web browser cookies too.)

Since both seem to solve what has been a frustrating error with no obvious cause I'll take it working again as a bonus without necessarily having found the cause.

Of course that particular error message ("An error occurred, please try again later") also seems to be a generic one used for many causes (including, I think, the video having been deleted) this may not be the only fix. But I'm hopeful it solved my immediate problem. (Going through to the YouTube site seems to be a useful way to narrow down the list of possible causes; if it plays on the YouTube site but not embedded it's less likely to be a YouTube backend issue.)