Background js doesn't run after productionization

I’m working on an extension with source that can be found here: https://github.com/rickyvetter/reason-tools/

I can run an unminified version on FF no problem. But my build step (specifically uglify) seems to make it so Background.bundle.js never loads. The minified extension works as expected in Chrome, but in FF it runs as if Background.bundle.js didn’t exist. The debugger shows no errors of any kind, but Background.bundle.js is not listed in the sources inside of the debugger.

How can I start to understand this error? Is there a way to see why files don’t show up in the debugger?

not listed in the sources inside of the debugger

Firefox tries to “mute” minified scripts, because nobody really wants to debut those, without source maps anyway. That could be a reason why they don’t show up.

But, why are you minifing anyway (honest question)? As far as I know there are two motivations to do so:

  • have smaller/less files to serve and
  • hide your source code (at least a bit).
    Neither apply in the case of extensions …

The background file is ~6.5MB without minification. It won’t pass the automated review process without it.

It seems like a generally good idea to run dead code elimination even on extensions - even if it doesn’t save a whole lot in practice, and eventually I might want this same code to run on a website as well.

I’ll try adding source maps to the output and see if that lists the file - but it should show up if there is an error in it - regardless of minification, correct?

Not sure, but at least the error should be visible somewhere, as should at least console.error statements (anything “below” .error may actually be hidden too).
And stack traces should contain your mangled functions too.

And 6.5MB code is … uh, wow.

It seems like a generally good idea to run dead code elimination even on extensions

If you trust the tool to know what code really is dead, sure. But it is also really nice to debug the code you actually wrote. And since you are writing an extension that only targets modern Browsers (at least Firefox must be version ~47+), you don’t need transpilers to be able to write decent code. And once you have debugged you code, why would you want to change it and risk that one of your tools makes changes that, well, are actually changes?

I don’t see any errors of any kind when running the extension.

it is also really nice to debug the code you actually wrote

The original code is written in OCaml - so I’m never going to be able to debug the code I actually wrote. Might as well make use of the tooling at hand to deliver the smallest correct set of code if I have to use source maps to debug regardless.

And 6.5MB code is … uh, wow.

It has an OCaml parser, compiler and two pretty printers compiled to JS. It’s a lot - but not too bad all things considered :slight_smile: