Skip to content

Resizing views on Electron 32 #47

@aadcg

Description

@aadcg

It used to be trivial to resize a view bound to a window via the deprecated setAutoResize. The new API that replaces BrowserView, WebContentsView, doesn't implement it.

It can be done via listeners but the current naive implementation (see add-bounded-view) doesn't sanitize those when the view is removed. Anyway, it isn't hard to imagine a situation where a window holds 10 views (tabs).

(node:151252) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 
11 resize listeners added to [BrowserWindow]. 
MaxListeners is 10. 
Use emitter.setMaxListeners() to increase limit

While it is trivial to silence these warning (as per below), let's keep it as a remainder.

modified   source/server.js
@@ -13,11 +13,15 @@ if (process.argv.length != 3) {
 const path = require('node:path')
 const nodejs_net = require('node:net');
 const fs = require('node:fs');
+const emitter = require('node:events');
 // The architecture of protocol handling resorts to a tmp file, meaning that the
 // main JS location may differ from the location of the current file.
 const SynchronousSocket = require(path.resolve('node_modules/synchronous-socket'));
 const { app, ipcMain, BrowserWindow, WebContentsView, webContents, protocol, net } = require('electron')
 
+emitter.setMaxListeners(0)
+
 app.on('ready', () => {
     const server = nodejs_net.createServer((socket) => {
         socket.on('data', (data) => {

Hopefully, Electron will fix the issue, see electron/electron#43802.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions