Pular para o conteúdo principal
ProdutosFerramentas de desktopTASTECADVisualização de desenhosTASTEFILESGerenciamento de arquivosTASTEFTPTransferência de arquivosTASTESSHEspaço de trabalho remotoTASTEZIPCompactação e extraçãoTASTEWINMGerenciamento de arquivosFerramentas para desenvolvedoresTASTECODEAmbiente de desenvolvimento integrado para RustTASTESTUDIOAmbiente integrado de desenvolvimento e testesTASTEETLIntegração de dados (ETL)ServidoresTASTEREMOTEServidor de área de trabalho remotaTASTEGEOServidor geoespacialTASTEMAILEspaço de trabalho de e-mailInvestimentosTASTESTOCKAplicativo desktop de negociação automática de açõesComeçarDownloadsDocumentaçãoComprarTodos os produtos
Marketplace
Notícias
TecnologiaNotíciasNotícias de desenvolvimento de hojeDocumentaçãoLinguagens de programaçãoRustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartFrameworks de front-end webNext.jsReactVue.js · NuxtSvelteKitAngularFrameworks de servidorSpring BootDjangoFastAPIASP.NET CoreNestJS · ExpressFrameworks de apps e desktopTauriFlutterReact NativeElectronAlgoritmosFundamentos de algoritmosAlgoritmos essenciaisAlgoritmos avançadosAlgoritmos práticos
ComunidadeProjetosRegistros de desenvolvimentoPromptsProblemas de ferramentas de IAVitrineGuia da comunidade
ColaboreTransferência técnicaConstrução de siteConstrução de app de desktopPipeline de lançamento e pagamentoParceiro de vendasContato
ServiçosÁrea de trabalho remotaPacotes de instalação sob medida
TASTEDEV
Produtos

Ferramentas de desktop

TASTECADDesenhos complexos, abertos com levezaTASTEFILESSó os arquivos de que você precisa, o mais rápido possívelTASTEFTPO caminho mais organizado para seus arquivosTASTESSHEntre você e o servidor, uma conexão mais sólidaTASTEZIPCompacte mais rápido, extraia com mais segurançaTASTEWINMUm gerenciador de arquivos de dois painéis feito para o teclado

Ferramentas para desenvolvedores

TASTECODEEdite, compile, depure e teste apps Rust em uma única janelaTASTESTUDIODa edição aos testes remotos e às correções com IA aprovadasTASTEETLMova dados de olho nos valores

Servidores

TASTEREMOTEUma área de trabalho remota rodando no seu próprio servidorTASTEGEOUm servidor geoespacial compatível com o GeoServer, reconstruído em RustTASTEMAILRetome o controle do seu e-mail

Investimentos

TASTESTOCKNegociação automática de ações pelas regras que você define: quando e o quê

Começar

DownloadsVersões mais recentes de cada produtoDocsComo usar cada produtoComprarAssinaturas e licenças perpétuasTodos os produtosTodos os produtos de relance
Todos os produtos
MarketplaceNotícias
Tecnologia

Notícias

Notícias de desenvolvimento de hojeAnúncios oficiais de linguagens, frameworks, GitHub e IADocumentaçãoGuias de linguagens, frameworks e algoritmos

Linguagens de programação

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

Frameworks

Frameworks de front-end webNext.jsReactVue.js · NuxtSvelteKitAngular
Frameworks de servidorSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
Frameworks de apps e desktopTauriFlutterReact NativeElectron

Algoritmos

Fundamentos de algoritmosAnálise de complexidade · Ordenação · Busca · Estruturas de dados básicas · Árvores e heapsAlgoritmos essenciaisBusca em grafos · Caminho mínimo e árvore geradora mínima · Programação dinâmica · Algoritmos gulosos · Divisão e conquista · BacktrackingAlgoritmos avançadosAlgoritmos de strings · Matemática e teoria dos números · Manipulação de bits · Árvores de segmentos · Union-FindAlgoritmos práticosEstratégia para entrevistas de código · Cache LRU · Limitação de taxa · Hashing consistente
Toda a documentação de desenvolvimento
Comunidade
ProjetosDescubra criadores e trabalhosRegistros de desenvolvimentoDecisões e aprendizadosPromptsInstruções reutilizáveisProblemas de ferramentas de IAProblemas e contornos de Claude, Codex, GeminiVitrineResultados concluídosGuia da comunidadeComo construímos em aberto
Colabore
Transferência técnicaApps nativos em Rust e eguiConstrução de site10 idiomas, contas, documentação e downloadsConstrução de app de desktopRust e egui, sem WebViewPipeline de lançamento e pagamentoAssinatura, MSI, deb, rpm, AppImage, hashesParceiro de vendasRecomende e ganhe 30%ContatoDesenvolvimento, parcerias e investimento
Serviços
Área de trabalho remotaAcesse seu computador pelo navegadorPacotes de instalação sob medidaSó o necessário, configurações pré-carregadas
Comprar
PT
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
Entrar
Entrar
TASTEDEV

De pequenas ferramentas a um desenvolvimento melhor.

support@tastedev.netApoiar TASTEDEV
ProdutosLinha de produtosComprarDocsDownloadsMarketplaceSuporte
ComunidadeProjetosRegistros de desenvolvimentoPromptsProblemas de ferramentas de IAVitrine
PolíticasSobre nósPolítica de privacidadeTermos de usoTermos de assinaturaReembolsoDiretrizes da comunidade
ContaEntrarCriar conta
Visitantes
Hoje
Ontem
Visualizações totais
Empresa
GXSOFT
Representante
CHOI YOUNG GU
Número de registro comercial
853-44-00368
Endereço
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
Telefone
+82-10-4404-1523
E-mail
whitecalvin@tastedev.net
Responsável pela privacidade
CHOI YOUNG GU

© 2026 TASTEDEVAs informações dos produtos se baseiam em fontes de desenvolvimento verificadas.Lançado · em melhoria

Documentação de Electron
Electron
Getting Started with ElectronProject StructureCore ConceptsData and StateTestingDeployment
Discussões

Guia de Electron · 3/6

Core Concepts

Por enquanto, este capítulo está disponível apenas em inglês.

Using Electron well means understanding its process model, how processes talk to each other over IPC, and the security model built on top of both. This chapter covers BrowserWindow, ipcMain and ipcRenderer, contextBridge, context isolation, and the security checklist.

The process model

Electron inherits Chromium's multi-process architecture.

  • Main process: exactly one per app, running in a Node.js environment. It owns the app lifecycle (app), windows (BrowserWindow), menus, the tray, dialogs, and other native features.
  • Renderer processes: one per window (strictly, per webContents), each running a web page. By default they have no Node.js access.
  • Utility processes: Node.js child processes started from the main process with utilityProcess.fork(). Use them to move heavy computation or crash-prone work out of the main process.

If the main process is blocked by a long task, every window appears frozen. Move heavy work to asynchronous APIs or a utility process.

// main.js
const { utilityProcess } = require('electron')
const path = require('node:path')

const child = utilityProcess.fork(path.join(__dirname, 'worker.js'))
child.on('message', (result) => console.log('result:', result))
child.postMessage({ numbers: [1, 2, 3] })

// worker.js
process.parentPort.on('message', (event) => {
  const sum = event.data.numbers.reduce((a, b) => a + b, 0)
  process.parentPort.postMessage(sum)
})

BrowserWindow

A BrowserWindow creates one native window and the renderer inside it. Alongside window options such as size, frame, and minimum size, webPreferences sets the renderer's security options.

const win = new BrowserWindow({
  width: 1000,
  height: 700,
  minWidth: 600,
  show: false, // show once content is ready to avoid a flash
  webPreferences: {
    preload: path.join(__dirname, 'preload.js'),
    contextIsolation: true, // default
    nodeIntegration: false, // default
    sandbox: true,          // default
  },
})

win.once('ready-to-show', () => win.show())
win.loadFile('index.html')

contextIsolation, nodeIntegration: false, and sandbox are already the defaults in current Electron. Spelling them out documents the intent and makes an accidental change easy to spot in review.

IPC: talking between processes

Renderers cannot reach the operating system directly, so they ask the main process over IPC. The most common pattern is request and response: register a handler in the main process with ipcMain.handle, call it from the renderer side (the preload) with , and receive the result as a Promise.

Dúvidas sobre este capítulo?
Capítulo anteriorProject StructurePróximo capítuloData and State
ipcRenderer.invoke
// main.js
const { ipcMain, dialog } = require('electron')

ipcMain.handle('dialog:openFile', async (event) => {
  const { canceled, filePaths } = await dialog.showOpenDialog({ properties: ['openFile'] })
  return canceled ? null : filePaths[0]
})
// preload.js
const { contextBridge, ipcRenderer } = require('electron')

contextBridge.exposeInMainWorld('api', {
  openFile: () => ipcRenderer.invoke('dialog:openFile'),
  setTitle: (title) => ipcRenderer.send('set-title', title),
  onUpdateCounter: (callback) => {
    ipcRenderer.on('update-counter', (_event, value) => callback(value))
  },
})

Fire-and-forget messages use ipcRenderer.send with ipcMain.on. When the main process needs to notify a renderer first, it calls win.webContents.send, and the preload listens with ipcRenderer.on and forwards the value to a callback.

// main.js
ipcMain.on('set-title', (event, title) => {
  const win = BrowserWindow.fromWebContents(event.sender)
  win.setTitle(title)
})

win.webContents.send('update-counter', 1)

// renderer.js
document.getElementById('open').addEventListener('click', async () => {
  const filePath = await window.api.openFile()
  if (filePath) document.getElementById('file').textContent = filePath
})
window.api.onUpdateCounter((value) => console.log('counter:', value))

contextBridge and context isolation

With context isolation enabled, the preload script and the web page run in separate JavaScript worlds. Scripts on the page cannot tamper with the preload's variables or with Electron APIs. The only passage between the two worlds is contextBridge.exposeInMainWorld; only the functions and values passed through it are visible to the page.

Exposing the entire ipcRenderer object would let the page send messages on any channel and defeat the isolation. Expose narrow, purpose-built functions as in the example above, and do not hand the raw event object to page callbacks.

The security checklist

The heart of Electron's official security checklist:

  1. Do not enable nodeIntegration in renderers.
  2. Do not disable contextIsolation or sandbox.
  3. Load remote content only over HTTPS, and never give untrusted content access to preload features.
  4. Set a Content Security Policy on every page.
  5. Validate the sender (event.senderFrame) and the arguments of every IPC message.
  6. Restrict new windows and navigation to unexpected destinations.
  7. Pass only validated URLs to shell.openExternal.
  8. Keep Electron on a currently supported version.
win.webContents.setWindowOpenHandler(({ url }) => {
  if (url.startsWith('https://example.com/')) shell.openExternal(url)
  return { action: 'deny' }
})

win.webContents.on('will-navigate', (event, url) => {
  if (!url.startsWith('file://')) event.preventDefault()
})

Summary

  • There is one main process and one renderer per window; heavy work can move to a utility process.
  • Use ipcMain.handle with ipcRenderer.invoke for request and response, send with on for one-way messages, and webContents.send from main to renderer.
  • Under context isolation, expose a narrow API through contextBridge.
  • Follow the security checklist: keep Node.js out of renderers, and apply a CSP, IPC validation, and navigation limits.

0 comentários

Principais comentáriosMais recentes primeiro

Fazer login · Faça login para deixar um comentário.