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

無法在渲染器進程中使用 Node.js API

Unable to use Node.js APIs in renderer process(無法在渲染器進程中使用 Node.js API)
本文介紹了無法在渲染器進程中使用 Node.js API的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

無法在電子中使用任何電子或節(jié)點相關(guān)操作.獲取錯誤過程未定義.我檢查了他們指導(dǎo)添加節(jié)點支持的各個地方,但這已經(jīng)完成所以卡在這里我的主要應(yīng)用程序代碼是

Unable to use any electron or node related operations in electron . Getting error process not defined. I Checked at various places they guide to add node Support but that is already Done so stucked here My Main Application code is

const electron = require("electron");
const { app, BrowserWindow } = electron;

function createWindow() {
  const win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: { nodeIntegration: true },
  });

  win.loadFile("index.html");
}

app.whenReady().then(createWindow);

app.on("window-all-closed", () => {
  if (process.platform !== "darwin") {
    app.quit();
  }
});

app.on("activate", () => {
  if (BrowserWindow.getAllWindows().length === 0) {
    createWindow();
  }
});

還有Index.html

And Index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Hello World!</title>
  </head>
  <body style="background: white">
    <h1>Hello World!</h1>
    <p>
      We are using node
      <script>
        document.write(process.versions.node);
      </script>
      , Chrome
      <script>
        document.write(process.versions.chrome);
      </script>
      , and Electron
      <script>
        document.write(process.versions.electron);
      </script>
      .
    </p>
  </body>
</html>

推薦答案

更新:下面的答案是一種解決方法.您不應(yīng)禁用 contextIsolation,也不應(yīng)啟用 nodeIntegration.相反,您應(yīng)該使用 預(yù)加載腳本 和 contextBridge API.

Update: the answer below is a workaround. You should not disable contextIsolation and you should not enable nodeIntegration. Instead you should use a preload script and the contextBridge API.

在 Electron 12 中,contextIsolation 現(xiàn)在默認為 true

In Electron 12, contextIsolation is now by default true

如果您將其設(shè)置為 false,您將可以在渲染器進程中訪問 Node.js API

If you set it to false, you will have access to Node.js APIs in the renderer process

function createWindow() {
  const win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: { 
     contextIsolation: false,
     nodeIntegration: true
    },
  });

  win.loadFile("index.html");
}

??需要注意的是,不推薦這樣做!

Electron 維護者更改默認值是有充分理由的.請參閱此討論

There's a good reason why Electron maintainers changed the default value. See this discussion

如果沒有 contextIsolation,渲染器進程中運行的任何代碼都可以很容易地進入 Electron 內(nèi)部或您的預(yù)加載腳本,并執(zhí)行您不希望任意網(wǎng)站執(zhí)行的特權(quán)操作.

Without contextIsolation any code running in a renderer process can quite easily reach into Electron internals or your preload script and perform privileged actions that you don't want arbitrary websites to be doing.

這篇關(guān)于無法在渲染器進程中使用 Node.js API的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 頻道中的消息?)
how to make my bot mention the person who gave that bot command(如何讓我的機器人提及發(fā)出該機器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修復(fù)必須使用導(dǎo)入來加載 ES 模塊 discord.js)
How to list all members from a specific server?(如何列出來自特定服務(wù)器的所有成員?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修復(fù)“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服務(wù)器時的歡迎消息)
主站蜘蛛池模板: 久久99精品久久久久久国产越南 | 亚洲精品一区二区在线观看 | 一区二区在线免费观看视频 | 久久久久久亚洲精品 | 欧美日韩精品影院 | 91视频国产一区 | 在线视频亚洲 | 日韩精品在线播放 | 精品久久国产 | 久久精品中文字幕 | 免费看片国产 | 日韩伦理一区二区 | 911精品国产 | 国产午夜精品久久久 | 日韩免费| 九九热在线视频免费观看 | 国产成人精品a视频一区www | 九九色九九 | 99re视频在线 | 在线国产视频 | 国产黄色在线观看 | 亚洲视频国产 | 中文字幕免费观看 | 中文字幕久久精品 | 2019精品手机国产品在线 | 成人妇女免费播放久久久 | 一区二区免费 | 人人人干 | 精品国产一区二区三区性色av | 久久久高清| 色又黄又爽网站www久久 | 久久久久久久久久久久久久久久久久久久 | 91在线免费视频 | 日韩a在线观看 | 亚洲欧美日韩系列 | 欧美视频xxx| 亚洲精品天堂 | 国产精品久久久久久久岛一牛影视 | 午夜寂寞影院列表 | 91色视频在线 | 精品国产乱码久久久久久果冻传媒 |