Skip to content

Support custom names for "browser" field resolution

I'm packaging WebTorrent so it can be used in a Chrome App environment. This is for the built-in torrent support in Brave Browser.

The "browser" field is automatically used during bundling, but for Chrome Apps I'd like to do different substitutions than for normal browser. Specifically, I'd like to use e.g. chrome-net instead of net since Chrome Apps have access to raw sockets, but normal browsers do not. Therefore, I cannot add this substitution to the 'browser' field without breaking the normal browser build.

What I really need is a way to specify what field name in package.json should be used for the browser field resolution, with "browser" being the default.

Fortunately, browser-resolve already support such an option! The browser option allows the user to select which property name to use from package.json. It defaults to "browser".

I'd like to update the existing config option browserField to accept a string value, e.g. { browserField: 'chromeapp' } for this exact purpose. Currently, this config option is only used to disable the browser field entirely, e.g.{ browserField: false }, so we can add a new string option relatively easily. I think this is cleanest.

What do folks think?