Closed Bug 961987 Opened 10 years ago Closed 10 years ago

Duplicate AdSense ad blows away theportugalnews.com if navigator.userAgent contains "Android" token

Categories

(Web Compatibility :: Site Reports, defect)

All
Android
defect
Not set
normal

Tracking

(Not tracked)

VERIFIED WORKSFORME

People

(Reporter: kbrosnan, Assigned: karlcow)

References

()

Details

(Whiteboard: [contactready][clientsniff][country-pt])

Reporting for http://forums.mozillazine.org/viewtopic.php?f=47&t=2791577

Opening http://www.theportugalnews.com/ in Firefox for Android results in the page briefly displaying as expected. Shortly there after a GET request is made which results in a HTTP 204 error. Then no content is shown.
OK, I think there's a ton going on here.


With a desktop UA, I get this in the console:
"A call to document.write() from an asynchronously-loaded external script was ignored. show_ads.js:29"

With a mobile UA, the page loads, and then is quickly blown away. Seemingly because the doc.write() succeeded.

Way down at the bottom of the page,
$(document).ready(function(e) {
    if(!($.browser.msie  && parseInt($.browser.version, 10) === 7)) {
        //console.log($($('.left-column').html()).find('script').remove())
        $('.left-right-column').html( $('.left-column').html() );
    }
});

Which corresponds to this markup:

<!-- opera bug -->
<div class="twocol left-right-column"></div>

Inside of .left-column, we have:

<div class="pub border">
                <script type="text/javascript"><!--
                google_ad_client = "pub-7032279059306465";
                google_ad_slot = "0131639205";
                google_ad_width = 120;
                google_ad_height = 600;
                //-->
                </script>
                <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
            </div>

So my current theory is the page is parsed, the google ad in <div class="left-column"> begins to fetch an ad, then DOMContentLoaded fires (which should trigger the $(doc).ready callback), and the content from <div class="left-column"> is copied into <div class="twocol left-right-column"></div>.

For whatever reason, that blows away the page. Commenting out that script (or removing <div class="twocol left-right-column"></div>) "fixes" the page. 

Now I wonder why this only happens for mobile UAs. Possibly show_ads.js is making some assumptions about desktop vs mobile?
Note that this behavior happens in Chrome too, if you spoof the UA string to be Chrome Mobile or Firefox Mobile but NOT iOS or BlackBerry.
Whiteboard: [notcontactready][clientsniff][country-pt]
The desktop case doc.write (which the browser ignores) is:

m.write(['<ins style="display:inline-table;', h, '"><ins id="', f.id +
        "_anchor", '" style="display:block;', h, '">', g.join(" "), "</ins></ins>"
      ].join(""));

The "Android" case is :

if (c) window.google_loader_used = "sb", window.google_start_time = v, ob(window, window), document.write(kb());

Where c is (re-)defined here: 

(c = !1 === window.google_enable_async) || (c = navigator.userAgent, Ba.test(c) ? c = !1 : (void 0 !== window.google_async_for_oa_experiment || !Ca.test(navigator.userAgent) || Ba.test(navigator.userAgent) || (window.google_async_for_oa_experiment = L(["E", "C"], ia)), c = Ca.test(c) ?
      "E" === window.google_async_for_oa_experiment : !0), c = !c || window.google_container_id || window.google_ad_output && "html" != window.google_ad_output);

Earlier on Ca = /Android/; is declared, so that's likely why Fennec and Chrome Mobile are hitting this codepath.
Just to make it clearer, these are in the Google scripts. Just to make it clear if we should contact Google or Portugal News. My impression is that it is on Google side.
Yes, I believe we need to contact Google about the show_ads.js script. The site is doing a weird workaround (apparently for Opera) by copying the markup for the ad--among other things--which results in two ads being injected (one is hidden via div.left-right-column {display:none;}). 

However, if the c variable mentioned in Comment 3 is "false" (as will be the case in any UA without an "Android" token in the UA--Desktop, Firefox OS, etc), the page works (double ads and all). Presumably that 2nd ad is created after the document is loaded and calls document.write() in a destructive way for non-WebKit Android browsers.
Whiteboard: [notcontactready][clientsniff][country-pt] → [contactready][clientsniff][country-pt]
Summary: The Portugal News makes a GET which results in a HTTP 204 → Duplicate AdSense ad blows away theportugalnews.com if navigator.userAgent contains "Android" token
Assignee: nobody → kdubost
Good work on the analysis, Mike! Is it still a problem though? I see a sort of "flash" of white when I think the page is done loading, but then it renders OK.
Flags: needinfo?(kbrosnan)
WFM
Status: NEW → RESOLVED
Closed: 10 years ago
Flags: needinfo?(kbrosnan)
Resolution: --- → WORKSFORME
Yeah, WFM too (sorry for missing your question from 3 months ago Hallvord >_>)
Status: RESOLVED → VERIFIED
Product: Tech Evangelism → Web Compatibility
Component: Mobile → Site Reports
You need to log in before you can comment on or make changes to this bug.