久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 Electron 渲染器進程中創建子窗口時如何修復

How to fix BrowserWindow is not a constructor error when creating child window in Electron renderer process(在 Electron 渲染器進程中創建子窗口時如何修復 BrowserWindow 不是構造函數錯誤) - IT屋-程序員軟件開發技術
本文介紹了在 Electron 渲染器進程中創建子窗口時如何修復 BrowserWindow 不是構造函數錯誤的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在使用 electron 構建一個包含兩個窗口的應用程序.我正在嘗試從渲染器進程內部打開第二個窗口,執行以下操作:

I'm using electron to build an application that includes two windows. I'm trying to open a second window from inside renderer process doing something like:

const electron = require('electron');
const BrowserWindow = electron.BrowserWindow;

const childWindow = new BrowserWindow({
   width: 800,
   height: 600
});

我收到一個錯誤提示

BrowserWindow 不是構造函數.

BrowserWindow is not a constructor.

我的另一個選擇是使用 window.open,但這并不理想,因為它返回 BrowserWindowProxy 對象,它的功能有限.

My other option is to use window.open, but that is not ideal since that returns BrowserWindowProxy object, which has limited functionality.

推薦答案

我發現我需要做的就是使用 remote 模塊.Electron 不允許直接從渲染進程創建瀏覽器窗口,因為它 (BrowserWindow) 需要 ipc 模塊與主進程通信.電子文檔說:

I found that all I needed to do was to use the remote module. Electron doesn't allow to directly create a browser window from the renderer process, because it (BrowserWindow) requires ipc module to communicate with the main process. Electron documentation says:

在 Electron 中,與 GUI 相關的模塊(如對話框、菜單等)僅在主進程中可用,在渲染器進程中不可用.為了在渲染器進程中使用它們,需要 ipc 模塊將進程間消息發送到主進程.

In Electron, GUI-related modules (such as dialog, menu etc.) are only available in the main process, not in the renderer process. In order to use them from the renderer process, the ipc module is necessary to send inter-process messages to the main process.

所以,new electron.BrowserWindow() 不起作用.但是,使用 remote 模塊正確設置了與主進程的進程間通信,以下修改后的代碼對我有用:

So, new electron.BrowserWindow() doesn't work. However, using remote module correctly sets up inter-process communicating with the main process and the following modified code works for me:

const electron = require('electron');
const BrowserWindow = electron.remote.BrowserWindow;

const childWindow = new BrowserWindow({
   width: 800,
   height: 600
});

remote 模塊更完整的解釋在這里:https://electron.atom.io/docs/api/remote/

A more complete explanation of remote module is here: https://electron.atom.io/docs/api/remote/

這篇關于在 Electron 渲染器進程中創建子窗口時如何修復 BrowserWindow 不是構造函數錯誤的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

mainWindow.loadURL(quot;https://localhost:3000/quot;) show white screen on Electron app(mainWindow.loadURL(https://localhost:3000/) 在 Electron 應用程序上顯示白屏)
Electron webContents executeJavaScript : Cannot execute script on second on loadURL(Electron webContents executeJavaScript:無法在第二個 loadURL 上執行腳本)
how to use electron browser window inside components in angular-cli?(如何在angular-cli的組件內使用電子瀏覽器窗口?)
ElectronJS - sharing redux store between windows?(ElectronJS - 在 Windows 之間共享 redux 存儲?)
How to access camera/webcamera inside electron app?(如何在電子應用程序中訪問相機/網絡攝像頭?)
How to getCurrentPosition via navigator.geolocation in Electron app?(如何通過電子應用程序中的 navigator.geolocation 獲取當前位置?)
主站蜘蛛池模板: www.久久 | 中文字幕综合 | av免费成人| 日韩欧美二区 | 成人一区二区三区在线观看 | 爱爱视频在线观看 | 99久久精品免费看国产四区 | 久久久www成人免费无遮挡大片 | 国产一区二区免费 | 神马影院一区二区三区 | 精品国产乱码久久久久久丨区2区 | 成人a免费| 福利社午夜影院 | 都市激情亚洲 | 国产偷自视频区视频 | 韩国精品一区二区三区 | 久久中文字幕一区 | 成人黄色av网址 | 欧美αv| 精品网 | 欧美日韩国产在线 | 亚洲国产日韩欧美 | 国产小视频在线 | 亚洲成年人免费网站 | 中文字幕一区二区三区精彩视频 | 欧美在线视频一区 | 午夜一区二区三区在线观看 | 在线免费观看一区二区 | 超碰免费在 | 亚洲精品一区二区三区中文字幕 | 国产成人精品一区二区三区在线观看 | 天天操天天干天天透 | 国产精品日产欧美久久久久 | 成人免费在线观看视频 | 色888www视频在线观看 | 欧美一级免费黄色片 | 国产一级特黄真人毛片 | 欧美一区二区三区免费电影 | 一级少妇女片 | 国产一级电影在线 | 久久久久国产一区二区三区 |