browser-extension
browser-extension copied to clipboard
Firefox extension fails to inject client if client was built with make dev
Problem
The Firefox extension fails to inject the client/build/boot.js
script of a development client if the client was built with make dev
as indicated here.
The error is that the injected script returned non-structured-clonable data, which is forbidden in Firefox (see here).
This does not happen if the client is built with yarn build
instead.
Chrome extension works OK with both ways of building the client.
Cause
The reason seems to be that the browserify boot bundle returns a function, which would not be structured clonable.
It doesn't happen when the client is built with yarn build
because here the NODE_ENV
environment variable is set to production
which causes the bundle to be minified, and the boot bundle's IIFE (immediately invoked function expression) is converted to a function expression (! function foo()
), which returns false
instead.
Solution
As suggested here, adding an undefined;
line at the end of the bundle solves the problem.
I just noticed a similar solution was proposed here before (commit https://github.com/hypothesis/browser-extension/pull/41/commits/2674d22cbfda70627ba225f99af815a457f1ab19), but then reverted because of a later change in the client.
@robertknight, do you recall what the syntax error was? I've just reapplied this fix and it seems to be working OK both in Chrome and Firefox.