Sitepatching updates

tweaking the broken code until it works, one site at a time

Why we broke BBC's iPlayer site

Site patching isn't risk-free. It's pretty powerful to be able to rewrite scripts and websites, and while we try to use it really carefully, things can go wrong. Very wrong. We now know that a patch added back in June recently broke BBC's iPlayer site completely. no

The reason we patched in the first place, was that Opera had a bug that broke something a previous iteration of iPlayer was doing.

The underlying bug is that if you through the DOM append a SCRIPT tag loading an external script, Opera's parser will pause until that script has loaded. Other browsers continue parsing up until some random time when the external script loads and runs. Hence Opera, unlike other browsers, does not let that external script see elements that are later in the source than the script that created the external script.

The way this bug manifested itself on the BBC iPlayer site was described as follows:

There is code in the HEAD of the document to add external scripts, and when they have loaded trigger among other things setBGUIDCookie(). However, the prependTo('body') call will fail if the parsing has not reached the body element.



As this was an Opera bug and not a site bug, we tried to push out a minor workaround while waiting for the big, complicated rewrite that will fix it properly. Script loading issues are, however, pretty hard to work around. So, we shipped something that would fake the response to document.getElementsByTagName() if you call it with the argument 'body' before the <body> element exists in the DOM:
document.getElementsByTagName=function(n){
	var elms=getElementsByTagName.call(this, n);
	if(elms.length==0 && n=='body')return [document.documentElement];
	return elms;
}


This resolved the "Add To Favourites does not work at BBC Iplayer" problem back in June. I even thought it was simple, elegant and relatively safe at the time.

Fast forward, and we meet the updated jQuery version's interesting feature detection code. They create an element for testing various things, add it to the document, do the gymnastics required and remove it again. If document.body exists, their test element will be a DIV, if not they create a BODY element. Because we pretended BODY exists, they would create a DIV element, append it before the HEAD element and do the odd stuff - for example setting innerHTML to a string of table markup. Hey, here's another obscure Opera bug: if you try to create a table with innerHTML on an element outside BODY, the table simply disappears. So jQuery broke in a fundamental way, and probably knocked out most of iPlayer's JS-based functionality. awww

This patch is of course removed from the upcoming browser.js release, and we'd like to sincerely apologise to the BBC developers for causing this problem.

Mixed bagAmazon, BBC, CNN, ++

Comments

ouzowtfouzoWTF Monday, September 12, 2011 7:40:15 PM

I feel with you. awww
We have a customer where we updated the software one month ago to fix some small bug and of course (thanks to Murphy) ran into a never ending bug party. Everything we tried to fix triggered another problem. Now, after four weeks of worries, headaches and excessive testing we finally fixed it (hopefully!) with a complete rewrite of the software. Mercifully this is the only customer with such problems.

Swapnil RustagiSwapnil99pro Tuesday, September 13, 2011 9:36:31 AM

"Opera's parser will pause until that script has loaded. Other browsers continue parsing up until some random time when the external script loads and runs."

Is this fixed in Ragnarok's updated build?

Ola P. Kleivenolak Tuesday, September 13, 2011 10:16:11 AM

This issue is not fixed in Ragnarök. There is ongoing work, but it is unlikely to be ready this year.

Mark SchenkMarkSchenk Tuesday, September 13, 2011 10:48:31 AM

I can imagine it took the BBC devs two days to debug the problem, as it is a combination of corner cases... Looking at some of the tweets, browser.js is getting a lot of undeserved flak. They don't realise it's also there to clean up after their mess when needed.

Glad it's fixed though, as I discovered the problem just as I was trying to tune in for my Doctor Who fix wink

Ola P. Kleivenolak Tuesday, September 13, 2011 11:38:45 AM

smile Indeed. I will buy celebration-cake the day browser.js has no purpose anymore. This particular case could have had a more elegant outcome, but as of now browser.js does more good than harm overall.

We're also talking to BBC about improving the process for cases like this - hoping to avoid similar incidents in the future.

Swapnil RustagiSwapnil99pro Tuesday, September 13, 2011 1:35:06 PM

Originally posted by olak:

I will buy celebration-cake the day browser.js has no purpose anymore.[/url]

I will organize a celebration party if I get the required but missing things in Opera. The list is long; quite long.

Rob Taylorrobtaylor84 Tuesday, September 13, 2011 5:27:56 PM

A big thank you to everyone at Opera for helping us out with this bug. I believe from what Nick here and Bruce at Opera have told me that a solution to stop this kind of thing happening again is already being discussed.

Again many thanks to everyone involved. I look forward to working with you guys again in future.

-@RobTaylor84

MyOpera team, please fix this!fearphage Tuesday, September 13, 2011 6:19:49 PM

It would be nice/convenient/fun to have a patch counter if the goal is to have 0 patches one day.

Hallvord R. M. Steenhallvors Wednesday, September 14, 2011 8:16:22 AM

Originally posted by robtaylor84:

A big thank you to everyone at Opera for helping us out with this bug.



No problem at all, Rob. In fact it's quite generous of you to say thanks when the problem was our fault in the first place wink

Originally posted by fearphage:

It would be nice/convenient/fun to have a patch counter



Nice idea. Let's see if we can figure out a way to do that.. smile

Aside: one of the tweets regarding this issue pointed me to http://blog.timvalenta.com/2011/06/16/why-you-should-disable-operas-browserjs/ which I had not seen before. I wrote a somewhat lengthy comment that some might find interesting.

ouzowtfouzoWTF Wednesday, September 14, 2011 10:15:15 AM

Originally posted by hallvors:

I wrote a somewhat lengthy comment that some might find interesting.


Yes, very interesting! smile

Hallvord R. M. Steenhallvors Wednesday, September 21, 2011 8:17:16 AM

Originally posted by fearphage:

It would be nice/convenient/fun to have a patch counter



Now live on opera.com/docs/browserjs/, fearphage. The newest browser.js releases will show how many patch entries from the database were included in that specific file. Thanks for the suggestion :-)

MyOpera team, please fix this!fearphage Wednesday, September 21, 2011 4:03:14 PM

Originally posted by hallvors:

Now live on opera.com/docs/browserjs/, fearphage

Sweet! I don't see it though. Where should it be located?

Current browser.js status: enabled.
Target version and time stamp of the active browser.js file is Opera Desktop 12.00 core 2.9.196, September 12, 2011 .

Ola P. Kleivenolak Wednesday, September 21, 2011 6:38:27 PM

You need a newer file (September 19 or later)

Cutting Spoonhellspork Wednesday, September 21, 2011 11:02:16 PM

Even after the "Check for Updates", I still show "Opera Desktop 11.50 core 2.9.168, September 12, 2011" Of course I am fully updated to the 11.51(1087) program.

I'll check if the 12.x branch fares any better...

Write a comment

New comments have been disabled for this post.