Firefox 3 Bug - More Info



This bug has been entered into the Mozilla bug system as Bug 445599 - Firefox 3 seems to "double initialize" Flash.


To reproduce this bug:

  1. Run Firefox 3 (bug still occuring as of Firefox 3.0.1)
  2. Navigate to *this* page - must run on a web server (not file system or localhost) due to Flash security
  3. Click on this link: The basic bug
  4. The bug occurs if you see more than one number between the horizontal lines on the test pages.
  5. If you do not see the bug, try clearing browser cache and refreshing, or just refreshing without clearing cache first, or navigating away from the test page and then back with the Back button.
  6. If you still do not see the bug, check which add-ons you have installed and enabled. The bug will not occur without certain add-ons, and different combinations of add-ons effect whether the bug will occur or not.
    I can reproduce the bug by disabling all add-ons EXCEPT Greasemonkey 0.8.20080609.0

Bug Ingredients

  1. A SWF created with Flash 8, 9, or 10 - the old Flash Professional 8 IDE or the new Flexbuilder Eclipse IDE.
  2. Using Flash Professional 8 IDE, attach the following ActionScript 2 code to Level 1, Frame 1:

    import flash.external.ExternalInterface;
    ExternalInterface.call( "asCallback", (new Date()).getMilliseconds() );
    stop();


    Note: the Flash FLA project file is a zip here.
  3. Publish the SWF as Firefox3Bug.swf
  4. See test_with_embed_tag.html for the HTML and JS code to reproduce the bug. Basically, it loads the SWF via the embed tag, and implements a method the SWF calls as soon as it is loaded.
  5. Follow the steps above under To reproduce this bug.

Some explanation

  1. The test page loads the SWF using an embed tag. Alternately, we can use a test page with SWFObject 1.5, which dynamically creates an embed tag in Firefox.
  2. The SWF's first frame runs and calls a JavaScript function named "asCallback", passing the milliseconds portion of the current time. This method is guaranteed to be called only once within the SWF lifetime.
  3. In JavaScript, the function "asCallback" is implemented to append the number to a span.
  4. If all goes as it should (and as it did in Firefox 2), the asCallback gets invoked only once.
  5. Unfortunately, asCallback gets called twice.
  6. Some slightly more complex ActionScript can confirm that the Flash runtime is being re-initialized. You can declare a "static" ActionScript 2 variable, assign 0 to it, pass that in the ExternalInterface call to asCallback, and then increment that static variable to 1. If somehow Flash was calling the ExternalInterface method twice within the same runtime, you would expect to see results of "0" and "1". However, you see results of "0" and "0". This can only mean that Flash was re-initialized.
  7. Since Flash in Firefox is implemented as a Netscape Plugin, this must mean the plugin itself is initialized twice. Some Firefox logging confirms this (see below).
  8. It only occurs with certain add-ons installed and enabled. Some digging around Bugzilla reveals claims that similar bugs occur when add-ons (or extensions) implement a "Content Policy".
  9. This breaks our RIA severely, and I suspect several others.
  10. We plan a patch to our RIA to use SWF Object 2.1, which dynamically inserts an object tag to load the SWF, as opposed to an embed tag.
  11. However, Firefox 3 still has a bug. The way it treats embed tags has changed since Firefox 2.
  12. So, the basic things needed for this bug to occur are:
    1. A SWF loaded via an emed tag.
    2. The SWF code calls back into JavaScript immediately upon being loaded.
    3. At least one add-on that implements a "Content Policy" is enabled.
  13. We are concerned that our work around simply masks the bug, and that the bug may still occur under other circumstances.

NSPR Logging

Using this batch file:

REM see firefox_3.0.1\mozilla\modules\plugin\base\public\nsPluginLogging.h
set NSPR_LOG_FILE=C:\firefox.log
SET NSPR_LOG_MODULES=Plugin:9, PluginNPP:9, PluginNPN:9
"C:\Program Files\Mozilla Firefox3\firefox.exe" "http://jcmsdev7.turner.com:82/rburke/Firefox3Bug/test_with_embed_tag.html"



Running the batch file cause Firefox 3 to launch and navigate to my test page. I then simply close Firefox 3 and examine the log file.

Here is the relevant snippet from the log. Note the parts that I made bold and red. These calls are unexpected and do not occus when logging the same scenario under Firefox 2. These calls prove that the Flash Plugin is being destroyed and then re-initialized.

***********************************************************************

0[332140]]: nsPluginHostImpl::InstantiateEmbeddedPlugin Begin mime=application/x-shockwave-flash, owner=1b5ac80, url=http://jcmsdev7.turner.com:82/rburke/Firefox3Bug/Firefox3Bug.swf

0[332140]]: nsPluginHostImpl::TrySetupPluginInstance Begin mime=application/x-shockwave-flash, owner=1b5ac80, url=http://jcmsdev7.turner.com:82/rburke/Firefox3Bug/Firefox3Bug.swf

0[332140]: nsPluginHostImpl::GetPluginFactory Begin mime=application/x-shockwave-flash, plugin=C:\WINDOWS\system32\Macromed\Flash\NPSWF32.dll

0[332140]: nsPluginHostImpl::UserAgent return=Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1

0[332140]: nsPluginHostImpl::TrySetupPluginInstance Finished mime=application/x-shockwave-flash, rv=0, owner=1b5ac80, url=http://jcmsdev7.turner.com:82/rburke/Firefox3Bug/Firefox3Bug.swf

0[332140]: nsPluginStreamListenerPeer::InitializeEmbedded url=http://jcmsdev7.turner.com:82/rburke/Firefox3Bug/Firefox3Bug.swf

0[332140]: nsPluginHostImpl::InstantiateEmbeddedPlugin Finished mime=application/x-shockwave-flash, rv=0, owner=1b5ac80, url=http://jcmsdev7.turner.com:82/rburke/Firefox3Bug/Firefox3Bug.swf

0[332140]: nsPluginStreamListenerPeer::OnStartRequest this=1fbee60 request=1cd572c mime=application/x-shockwave-flash, url=http://jcmsdev7.turner.com:82/rburke/Firefox3Bug/Firefox3Bug.swf

0[332140]: nsPluginStreamListenerPeer::OnDataAvailable this=1fbee60 request=1cd572c, offset=0, length=146, url=http://jcmsdev7.turner.com:82/rburke/Firefox3Bug/Firefox3Bug.swf

0[332140]: nsPluginStreamListenerPeer::OnStopRequest this=1fbee60 aStatus=0 request=1cd572c

0[332140]: nsPluginHostImpl::UserAgent return=Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1

0[332140]: nsPluginStreamListenerPeer::dtor this=1fbee60, url=http://jcmsdev7.turner.com:82/rburke/Firefox3Bug/Firefox3Bug.swf

0[332140]: nsPluginHostImpl::StopPluginInstance called instance=1fa5ac0

0[332140]: nsPluginHostImpl::InstantiateEmbeddedPlugin Begin mime=application/x-shockwave-flash, owner=1b5ac80, url=http://jcmsdev7.turner.com:82/rburke/Firefox3Bug/Firefox3Bug.swf

0[332140]: nsPluginHostImpl::TrySetupPluginInstance Begin mime=application/x-shockwave-flash, owner=1b5ac80, url=http://jcmsdev7.turner.com:82/rburke/Firefox3Bug/Firefox3Bug.swf

0[332140]: nsPluginHostImpl::GetPluginFactory Begin mime=application/x-shockwave-flash, plugin=C:\WINDOWS\system32\Macromed\Flash\NPSWF32.dll

0[332140]: nsPluginHostImpl::UserAgent return=Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1

0[332140]: nsPluginHostImpl::TrySetupPluginInstance Finished mime=application/x-shockwave-flash, rv=0, owner=1b5ac80, url=http://jcmsdev7.turner.com:82/rburke/Firefox3Bug/Firefox3Bug.swf

0[332140]: nsPluginStreamListenerPeer::InitializeEmbedded url=http://jcmsdev7.turner.com:82/rburke/Firefox3Bug/Firefox3Bug.swf

0[332140]: nsPluginHostImpl::InstantiateEmbeddedPlugin Finished mime=application/x-shockwave-flash, rv=0, owner=1b5ac80, url=http://jcmsdev7.turner.com:82/rburke/Firefox3Bug/Firefox3Bug.swf

0[332140]: nsPluginStreamListenerPeer::OnStartRequest this=25ba740 request=256d3fc mime=application/x-shockwave-flash, url=http://jcmsdev7.turner.com:82/rburke/Firefox3Bug/Firefox3Bug.swf

0[332140]: nsPluginStreamListenerPeer::OnDataAvailable this=25ba740 request=256d3fc, offset=0, length=146, url=http://jcmsdev7.turner.com:82/rburke/Firefox3Bug/Firefox3Bug.swf

0[332140]: nsPluginStreamListenerPeer::OnStopRequest this=25ba740 aStatus=0 request=256d3fc

0[332140]: nsPluginHostImpl::UserAgent return=Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1

0[332140]: nsPluginStreamListenerPeer::dtor this=25ba740, url=http://jcmsdev7.turner.com:82/rburke/Firefox3Bug/Firefox3Bug.swf

0[332140]: nsPluginHostImpl::StopPluginInstance called instance=1be1100

0[332140]: nsPluginHostImpl::Destroy Called

***********************************************************************