Skip to content

Commit c8b6695

Browse files
committed
docs: clarify differences between browser and node
1 parent eaf82cd commit c8b6695

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,22 @@ Closes the Store.
806806

807807
## Browser
808808

809+
> [!IMPORTANT]
810+
> The only protocol supported in the browser is MQTT over WebSockets, so you must use `ws://` or `wss://` URLs.
811+
812+
While in NodeJS the [ws](https://www.npmjs.com/package/ws) module is used, in the browser the [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) is used.
813+
814+
This is totally transparent to users except for the following:
815+
816+
- The `wsOption` is not supported in the browser.
817+
- Browser doesn't allow to catch many WebSocket errors for [security reasons](https://stackoverflow.com/a/31003057) as:
818+
819+
> Access to this information could allow a malicious Web page to gain information about your network, so they require browsers report all connection-time errors in an indistinguishable way.
820+
821+
So listening for `client.on('error')` may not catch all the errors you would get in NodeJS env.
822+
823+
### Bundle
824+
809825
MQTT.js is bundled using [esbuild](https://esbuild.github.io/). It is tested working with all bundlers like Webpack, Vite and React.
810826

811827
You can find all mqtt bundles versions in `dist` folder:
@@ -838,8 +854,6 @@ The MQTT.js bundle is available through <http://unpkg.com>, specifically
838854
at <https://unpkg.com/mqtt/dist/mqtt.min.js>.
839855
See <http://unpkg.com> for the full documentation on version ranges.
840856

841-
**Be sure to only use this bundle with `ws` or `wss` URLs in the browser. Others URL types will likey fail**
842-
843857
<a name="qos"></a>
844858

845859
## About QoS

0 commit comments

Comments
 (0)