Skip to content

Move Mozilla and Chrome specific download code into different files

The source/scripts/background.js file currently houses download code for both Mozilla and Chrome based APIs. This is toggled on an if statement depending if the downloads.ondeterminingfilename API exists.

We should separate this code into separate files:

  • source/scripts/background.js (for shared code)
  • source/scripts/background.chrome.js (for Chrome API compatible browsers)
  • source/scripts/background.mozilla.js (for Firefox only)

This can be achieved in Webpack:

// webpack.config.js

const getBackgroundScripts = (browser) => {
  let scripts = ['source/scripts/background.js'];
  if (browser === 'firefox') {
    scripts.push('source/scripts/background.mozilla.js');
    return scripts;
  }

  scripts.push('source/scripts/background.chrome.js');
  return scripts;
};

module.exports = {

  ....

  entry: {
    manifest: './source/manifest.json',
    background: getBackgroundScripts(targetBrowser),
    contentScript: './source/scripts/contentScript.js',
    options: './source/scripts/options.js',
  },

  ....
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information