-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Electron browser environment check #1877
Comments
@GuoSirius Could you submit a PR to fix the issue please? |
if (process.type === 'renderer') {
console.log('current Electron Renderer');
} else if (typeof process.electron !== 'undefined') {
console.log('current Electron Main');
} |
In fact, this test should not be placed here for judgment. Because the rendering process is also a browser environment, since it is a browser environment, it should go the browser logic. Otherwise, the ws module may be mistakenly loaded in the browser environment of the rendering process, and the ws module cannot run in the browser environment. If you do need to use the mqtt protocol in an electron application, it is recommended to put the connection establishment logic in the main process, and then use the interprocess communication mechanism to interact between the row rendering process and the main process. The rendering process must have a window and a document, but not necessarily a Node.js environment, depending on the configuration at instantiation time. With the main rendering process's responsibilities clearly divided, the browser environment's detection mechanism can maintain the previous standard judgment logic. |
The Electron main process owns all Node environments and can establish connections according to the logic of non-browser environments. The rendering process belongs to the browser environment and should follow the logic of the browser environment to establish the connection. Just because the rendering process has more process, Node, and other accessible environments than the normal browser environment, it should not be attributed to the Node environment. In this cross-end application, it is up to the user to decide which way to establish the connection. According to the needs, the connection can be established in the main process or the rendering process, rather than the application library to force detection to determine the protocol. According to the above convention, the is-browser.ts file is purely used to detect the browser environment, regardless of whether there are other factors, such as the main process or the rendering process. |
I answer to you in the PR |
MQTTjs Version
5.7.0
Broker
RabbitMQ
Environment
Electron Renderer & Browser
Description
Electron Renderer process still exist
electron
keyword, cannot check browser environmentMinimal Reproduction
Debug logs
The text was updated successfully, but these errors were encountered: