Note that there are some explanatory texts on larger screens.

plurals
  1. POUpgrading an addon to be compatible with Firefox 4.0, but trying to keep it compatible with 3.x also. Advice?
    primarykey
    data
    text
    <p>I have an add-on which was written for Firefox 3.6 and now I'm upgrading it for Firefox 4.0, while trying to also keep it compatible with 3.6. Does anyone have any experience with trying to do this, or tips on how to do it without the code getting too spaghetti-ish?</p> <p>There are a few places where keeping it compatible with both versions means doing something like this:</p> <pre><code>.myAddonClass { -moz-background-size: 100% 100%; /* Fx 3.x */ background-size: 100% 100%; /* Fx 4.x */ } </code></pre> <p>which produces a CSS warning in both versions. I can live with that. There are other places where I'm doing things like this:</p> <pre><code>/** get the current version of this addon */ function getVersion() { var version; if (Application.extensions) { // Fx 3.x version = Application.extensions.get('myaddon@example.com').version; } else { // Fx 4.x Components.utils.import('resource://gre/modules/AddonManager.jsm'); AddonManager.getAddonByID('myaddon@example.com', function(addon) { version = addon.version; }); sleepUntil(function() { return version; } } return version; } </code></pre> <p>(where sleepUntil is a utility function that uses the <a href="https://developer.mozilla.org/en/Code_snippets/Threads#Waiting_for_a_background_task_to_complete" rel="nofollow"><code>Thread.processNextEvent</code> technique</a>)</p> <p>Checking whether <code>Application.extensions</code> is defined seems cleaner than just checking the <code>Application.version</code> string directly, but maybe there's some flaw with that approach that I don't know about?</p> <p>I'm also running into issues trying to insert content into webpages. In one case, <code>doc.body.appendChild</code> was working in 3.x but not in 4.x, so I tried doing this:</p> <pre><code>try { // Fx 3.x doc.body.appendChild(myElement); } catch (e) { // Fx 4.x let span = doc.createElement('span'); doc.body.appendChild(span); span.innerHTML = outerHTML(myElement); } </code></pre> <p>The code above doesn't work, but if I insert a <code>throw new Error('')</code> just before <code>doc.body.appendChild(myElement)</code> then it does work, indicating that in Firefox 4, the <code>appendChild</code> call apparently modifies <code>myElement</code> in some way before it throws an error. I'm sure I can figure out how to get this particular code snippet to work, but I'm worried that I'll run into a lot more problems like this as well, so I want to see if anyone else has already gone through a similar process, and has any tips that I should be aware of.</p> <p>Sorry for the long-ish question. <strong>Here's what I'm really asking:</strong></p> <ol> <li>What advice do you have for trying to keep an addon compatible with both Firefox 3 and Firefox 4 at the same time?</li> <li>What do you think about the idea of branching the code so that we have one version for 3.x and another for 4.x? We would then have to apply any new features to both versions, and test them in both versions, etc.</li> <li>In general, is it better to test for the presence of the specific feature you want (like I did with <code>if (Application.extensions) ...</code> or try/catch) or to just check whether <code>Application.version</code> starts with '3' or '4'?</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload