hypothesis / hypothesis/browser-extension
Firefox extension fails to inject client if client was built with make dev
- Dominant language
- JavaScript
- Stars
- 553
- Forks
- 141
- PR merge metrics
- No merged PRs in 30d
Description
## 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](https://h.readthedocs.io/projects/client/en/latest/developers/developing/#running-the-client-from-the-browser-extension).
The error is that the injected script returned non-structured-clonable data, which is forbidden in Firefox (see [here](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/executeScript#Return_value)).
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](https://stackoverflow.com/a/44774834/10879911), 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](https://github.com/hypothesis/browser-extension/commit/f17401a0eb36de9ad28ca3c8b2ecd3c4d96b26f3#diff-b67911656ef5d18c4ae36cb6741b7965) 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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.