A browser sniffing warning: The trouble with Acid3 and TinyMCE

Forums » Dev.Opera » Archived Article Discussions

This topic has been closed. No new entries allowed.

Reason: You can now post comments on articles on Dev Opera

Forum rules and guidelines

You need to be logged in to post in the forums. If you do not have an account, please sign up first.

Go to last post

2. July 2008, 21:32:16

Opera Software

hallvors

Opera Software

Posts: 1776

A browser sniffing warning: The trouble with Acid3 and TinyMCE

In this article Hallvord Steen provides a warning about browser sniffing and why it is such a bad thing, by examining a recent bug discovered in Opera relating to compatibility with the TinyMCE editor. He also suggests a fix to this problem, involving "bug detection", a useful technique that can be applied to many other situations.

( Read the article )

--
My blog: miscoded
Stupid code from major websites uncovered and criticised
Contribute site fixes! - OTW&TA- all sites must work

3. July 2008, 07:19:29

JeroenH

Posts: 434

The article currently says "Access denied". Unfortunately, since it looks quite interesting!

3. July 2008, 07:20:56

Opera Software

hallvors

Opera Software

Posts: 1776

Hi JeroenH, can you get to it now? It works for me.
--
My blog: miscoded
Stupid code from major websites uncovered and criticised
Contribute site fixes! - OTW&TA- all sites must work

3. July 2008, 07:23:11

shadowk

Widget Samurai

Posts: 81

it still does not work smile "access denied"
>>May the Sky never fall on our HEAD

3. July 2008, 07:45:37

Opera Software

chrismills

Posts: 379

Originally posted by shadowk:

it still does not work "access denied"



*sigh* - somewhere along the line, a bug has been introduced into dev.opera.com, which has stopped me from publishing articles properly. The systems folk are working on it now.
Chris Mills
Developer Relations Manager
Editor, dev.opera.com and labs.opera.com

3. July 2008, 11:04:15

Opera Software

hallvors

Opera Software

Posts: 1776

Seems it's up now smile
--
My blog: miscoded
Stupid code from major websites uncovered and criticised
Contribute site fixes! - OTW&TA- all sites must work

3. July 2008, 11:24:08

Indeed, I can read it now, and it IS quite interesting! bigsmile

Very nice to see the history behind this particularly high-profile bug. Seeing the bug-detection code is very helpful too.
Web Site (Opera pages) : Blog
(currently using Opera 10 and a fairly recent v10.10 alpha)

3. July 2008, 19:52:39

petermichaux

Posts: 1

This type of feature testing is definitely the way to go and has always been part of feature testing/detection. Sometimes it isn't just enough to know an API is present but it must be tested to know that it works as it should. I wrote a couple articles on similar feature testing ideas:

http://peter.michaux.ca/article/7146
http://peter.michaux.ca/article/7217

I think rather than calling it "has_range_collapse_bug" I would call it something like "ranges_supported" to be positive and thinking in terms of progressive enhancements rather than thinking in terms of graceful degradation. I find it is more productive to think about progressive enhancements.

4. July 2008, 07:31:02

JeroenH

Posts: 434

It's working fine now. Thanks!

14. July 2008, 22:07:15 (edited)

xErath

javascript guru

Posts: 6588

You have good intentions Hallvord, but if developers started going bug detection, more than half of the code in most scripts, js frameworks and libraries would be bug detection code, thanks mostly to IE, and older versions of the other browsers.

I agree with you though !
For a collection of user scripts visit
http://my.opera.com/xErath/blog/

22. July 2008, 12:56:32

Opera Software

hallvors

Opera Software

Posts: 1776

Originally posted by xErath:

but if developers started going bug detection, more than half of the code in most scripts, js frameworks and libraries would be bug detection code



Maybe smile But then, much of the benefit of using frameworks and libraries presumably comes from their browser incompatibility workarounds - it's a major selling point for every library, so they should do it properly.
--
My blog: miscoded
Stupid code from major websites uncovered and criticised
Contribute site fixes! - OTW&TA- all sites must work

23. July 2008, 17:00:21

PadreSol

Posts: 28

I think most everyone would agree.
But if you want to actually get things done then browser-sniff hacks are inevitable.
So just make opera not report itself. Isn't the problem a much bigger issue?

Ideally no browser would report itself, wasn't that how things were originally?

There are no standards. The word standard should be excised from the lexicon.
At least the computer lexicon.

23. July 2008, 17:55:52

Opera Software

hallvors

Opera Software

Posts: 1776

Originally posted by PadreSol:

if you want to actually get things done then browser-sniff hacks are inevitable



I'm arguing that many if not most of the problems you need to work around can be detected without browser sniffing. If you can pull that off, your script will be technically sounder (plus it will be more likely to work without bugs in IE 12..)
--
My blog: miscoded
Stupid code from major websites uncovered and criticised
Contribute site fixes! - OTW&TA- all sites must work

29. July 2008, 16:26:18

Moxiecode

Posts: 8

There are a few problems with feature detection and bug detection. The example that is displayed in this article is a good case where we should have used bug detection since we should have known that Opera would eventually fix the bug.

The problem is that feature detection will fail when common javascript libraries like prototype or mootools are used since they patch in things that they feel are missing in the default API. So if we then look for a specific feature using something like:

if (document.attachEvent)
   yada;
else
   yada;
The above statement might run the first code chunk on non IE browsers even if we look for a IE specific feature since some odd script might have patched the document object and added in an attachEvent just to be more "compatible" but it might then instead produce odd bugs. The hasOwnProperty doesn't work correctly on IE on native objects so it can't be used in the above case. sad

There are two problems with bug detection some bugs can not be detected such some bug that craches the browser or produces some result that can't be reverted. The other problem is that the code size will increase a lot the suggested opera detection in this article is nice but it's large and if we had such code chunks for each little bug out scripts would be 10 times larger or more and our user base is already nagging about the script size. smile

But anyway, good article and feature and bug detection is the still the way to go if it's possible but I don't think the subject is blank and white sometimes you need to do sniffing but most of the time we don't need it and shouldn't use it.

30. July 2008, 11:23:15

Opera Software

hallvors

Opera Software

Posts: 1776

Good points smile

Originally posted by Moxiecode:

The above statement might run the first code chunk on non IE browsers even if we look for a IE specific feature



In some cases it might be possible and better to look for the feature you're going to use. You are not in any case guaranteed that all browsers with native support for attachEvent support everything IE does - or have the same bugs, depending on what you are looking for. Opera, for one, supports attachEvent but still doesn't have all features or bugs IE has.

code size will increase a lot the suggested opera detection in this article is nice but it's large and if we had such code chunks for each little bug out scripts would be 10 times larger



Indeed, though by exactly how much the code would grow I haven't tested this enough to work out. It would be an interesting study to take some popular library script, try to replace all instances of browser sniffing with equivalent bug/feature detection and see what impact it had on size and performance. I hope in most cases the trade-off would be worth it, especially as one of the major reasons I'd deploy something like TinyMCE instead of just an <iframe> with designMode on is to avoid having to deal with browser differences..
--
My blog: miscoded
Stupid code from major websites uncovered and criticised
Contribute site fixes! - OTW&TA- all sites must work

Forums » Dev.Opera » Archived Article Discussions