You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+16-2Lines changed: 16 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -806,6 +806,22 @@ Closes the Store.
806
806
807
807
## Browser
808
808
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
+
809
825
MQTT.js is bundled using [esbuild](https://esbuild.github.io/). It is tested working with all bundlers like Webpack, Vite and React.
810
826
811
827
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
838
854
at <https://unpkg.com/mqtt/dist/mqtt.min.js>.
839
855
See <http://unpkg.com> for the full documentation on version ranges.
840
856
841
-
**Be sure to only use this bundle with `ws` or `wss` URLs in the browser. Others URL types will likey fail**
0 commit comments