Incorrectly formatted html inconsistencies between DOM and what's displayed in firefox plugin

Posted by deadalnix on Stack Overflow See other posts from Stack Overflow or by deadalnix
Published on 2011-06-29T14:17:10Z Indexed on 2011/06/29 16:22 UTC
Read the original article Hit count: 402

I'm currently developing a firefox plugin. This plugin has to handle very crappy website that is really incorrectly formatted. I cannot modify these websites, so I have to handle them.

I reduced the bug I'm facing to a short sample of html (if this appellation is appropriate for an horror like this) :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Some title.</title>
    <!-- Oh fuck yes ! -->
    <div style="visability:hidden;">
        <a href="//example.com"> </a>
    </div>

<!-- If meta are reduced, then the bug disapears ! -->
<meta name="description" content="Homepage of Company.com, Company's corporate Web site" />
<meta name="keywords" content="Company, Company & Co., Inc., blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla" />
<meta http-equiv="Content-Language" content="en-US" />
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>

</head>
<body class="homePage">

<div class="globalWrapper"><a href="/page.html">My gorgeous link !</a></div>

</body>

</html>

When opening the webpage, « My gorgeous link ! » if displayed and clickable. However, when I'm exploring the DOM with Javascript into my plugin, everything behaves (DOM exploration and innerHTML property) like the code was this one :

<html>
<head>
<title>Some title.</title>
    <!-- Oh fuck yes ! -->
    </head><body><div style="visability:hidden;">
        <a href="//example.com"> </a>
    </div>

<!-- If meta are reduced, then the bug disapears ! -->
<meta name="description" content="Homepage of Company.com, Company's corporate Web site">
<meta name="keywords" content="Company, Company &amp; Co., Inc., blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla">
<meta http-equiv="Content-Language" content="en-US">
</body>
</html>

So, when exploring the DOM within the plugin, the document is somehow fixed by firefox. But this fixed DOM is inconsistent with what is in the webpage. Thus, my plugin doesn't behave as expected.

I'm really puzzled with that issue. The problem exists in both firefox 3.6 and firefox 4 (didn't tested firefox 5 yet). For example, reducing the meta, will fix the issue.

Where does this discrepancy come from ? How can I handle it ?

EDIT: With the answer I get, I think I should be a little more precise. I do know what firefow is doing when modifying the webpage in the second code snippet. The problem is the following one : « In the fixed DOM that I get into my plugin, the gorgeous link doesn't appear anywhere, but this link is actually visible on the webpage, and works. So the DOM I'm manipulating, and the DOM in the webpage are different - they are fixed in a different manner. » . So where does the difference come in the fixing behaviour, and how can I handle that, or, in other terms, how can I be aware, in my plugin, of the existance of the gorgeous link ?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about firefox