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

在 Electron 渲染器進(jìn)程中創(chuàng)建子窗口時(shí)如何修復(fù)

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

問題描述

我正在使用 electron 構(gòu)建一個(gè)包含兩個(gè)窗口的應(yīng)用程序.我正在嘗試從渲染器進(jìn)程內(nèi)部打開第二個(gè)窗口,執(zhí)行以下操作:

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
});

我收到一個(gè)錯(cuò)誤提示

BrowserWindow 不是構(gòu)造函數(shù).

BrowserWindow is not a constructor.

我的另一個(gè)選擇是使用 window.open,但這并不理想,因?yàn)樗祷?BrowserWindowProxy 對象,它的功能有限.

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

推薦答案

我發(fā)現(xiàn)我需要做的就是使用 remote 模塊.Electron 不允許直接從渲染進(jìn)程創(chuàng)建瀏覽器窗口,因?yàn)樗?(BrowserWindow) 需要 ipc 模塊與主進(jìn)程通信.電子文檔說:

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 相關(guān)的模塊(如對話框、菜單等)僅在主進(jìn)程中可用,在渲染器進(jìn)程中不可用.為了在渲染器進(jìn)程中使用它們,需要 ipc 模塊將進(jìn)程間消息發(fā)送到主進(jìn)程.

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 模塊正確設(shè)置了與主進(jìn)程的進(jìn)程間通信,以下修改后的代碼對我有用:

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/

這篇關(guān)于在 Electron 渲染器進(jìn)程中創(chuàng)建子窗口時(shí)如何修復(fù) BrowserWindow 不是構(gòu)造函數(shù)錯(cuò)誤的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

mainWindow.loadURL(quot;https://localhost:3000/quot;) show white screen on Electron app(mainWindow.loadURL(https://localhost:3000/) 在 Electron 應(yīng)用程序上顯示白屏)
Electron webContents executeJavaScript : Cannot execute script on second on loadURL(Electron webContents executeJavaScript:無法在第二個(gè) loadURL 上執(zhí)行腳本)
how to use electron browser window inside components in angular-cli?(如何在angular-cli的組件內(nèi)使用電子瀏覽器窗口?)
ElectronJS - sharing redux store between windows?(ElectronJS - 在 Windows 之間共享 redux 存儲(chǔ)?)
How to access camera/webcamera inside electron app?(如何在電子應(yīng)用程序中訪問相機(jī)/網(wǎng)絡(luò)攝像頭?)
How to getCurrentPosition via navigator.geolocation in Electron app?(如何通過電子應(yīng)用程序中的 navigator.geolocation 獲取當(dāng)前位置?)
主站蜘蛛池模板: 久久久精品网 | 日韩一级免费视频 | 日韩精品视频在线免费观看 | 婷婷色婷婷 | 亚洲国产天堂 | 亚洲精品一区二区在线观看 | 国产三级在线观看视频 | www.色网 | 在线观看欧美日韩视频 | 亚洲天码中字 | 黄色影院在线观看 | 久久激情视频 | 日本免费黄色网址 | 亚洲精品麻豆 | 天天操综合网 | 日韩国产在线播放 | 久久精品毛片 | avxxxxx| 超碰91在线| 日韩一区三区 | 成人黄色免费视频 | 成年人在线观看 | 97精品超碰一区二区三区 | 欧美成人激情视频 | 国产一级黄色录像 | 国产午夜激情 | 小镇姑娘国语版在线观看免费 | 中文字幕无人区二 | 午夜久久久久久久 | 瑟瑟视频在线观看 | 日韩精品在线一区二区 | 青青草视频在线观看 | 黑人精品xxx一区一二区 | 日韩在线播放视频 | 国产欧美精品一区二区三区 | 性av在线 | 午夜精品国产 | 毛片aaa | 国产亚洲欧美日韩高清 | 亚洲成人日韩 | 久艹在线 |