Why we broke BBC's iPlayer site
By Hallvord R. M. Steenhallvors. Monday, September 12, 2011 7:03:55 PM
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.
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.









ouzowtfouzoWTF # Monday, September 12, 2011 7:40:15 PM
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
Is this fixed in Ragnarok's updated build?
Ola P. Kleivenolak # Tuesday, September 13, 2011 10:16:11 AM
Mark SchenkMarkSchenk # Tuesday, September 13, 2011 10:48:31 AM
Glad it's fixed though, as I discovered the problem just as I was trying to tune in for my Doctor Who fix
Ola P. Kleivenolak # Tuesday, September 13, 2011 11:38:45 AM
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:
Rob Taylorrobtaylor84 # Tuesday, September 13, 2011 5:27:56 PM
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
Hallvord R. M. Steenhallvors # Wednesday, September 14, 2011 8:16:22 AM
Originally posted by robtaylor84:
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
Originally posted by fearphage:
Nice idea. Let's see if we can figure out a way to do that..
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:
Yes, very interesting!
Hallvord R. M. Steenhallvors # Wednesday, September 21, 2011 8:17:16 AM
Originally posted by fearphage:
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:
Sweet! I don't see it though. Where should it be located?Ola P. Kleivenolak # Wednesday, September 21, 2011 6:38:27 PM
Cutting Spoonhellspork # Wednesday, September 21, 2011 11:02:16 PM
I'll check if the 12.x branch fares any better...