




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























































































Question 1. Which process in Electron is responsible for creating native UI elements such as menus and the application lifecycle events? A) Renderer process B) Main process C) Preload script D) Worker thread Answer: B Explanation: The main process runs Node.js, controls the app’s lifecycle, and creates native UI components like BrowserWindow, Menu, and Tray.
Question 2. In the Electron multi‑process model, which of the following statements is true about the renderer process? A) It has full access to Node.js APIs by default in recent Electron versions. B) It can directly manipulate the file system without a preload script. C) It runs a Chromium instance to render web content. D) It manages the auto‑updater module. Answer: C Explanation: Each renderer process hosts a Chromium web page, rendering HTML/CSS/JS. Node.js access is optional and controlled via contextIsolation and preload scripts.
Question 3. What does the app.whenReady() promise resolve to? A) The main BrowserWindow instance. B) The Electron app module itself.
C) A boolean indicating if the OS is ready. D) Nothing; it simply signals that the app is ready. Answer: D Explanation: app.whenReady() resolves when the Electron initialization is complete, allowing safe creation of windows; it does not return a value.
Question 4. Which event is emitted when all windows of an Electron app are closed on macOS, but the app should stay active? A) window-all-closed B) quit C) activate D) before-quit Answer: C Explanation: On macOS, the activate event is emitted when the dock icon is clicked after all windows are closed, allowing the app to recreate a window.
Question 5. What is the primary security benefit of enabling contextIsolation in a renderer process? A) It disables the Chromium sandbox. B) It prevents the renderer from accessing Node.js globals directly. C) It allows the preload script to run in the same context as the page. D) It disables all IPC communication. Answer: B
Question 8. What is the difference between ipcRenderer.invoke and ipcRenderer.send? A) invoke is synchronous, send is asynchronous. B) invoke returns a promise that resolves with a response; send does not expect a response. C) invoke can only be used from the main process. D) There is no functional difference; they are aliases. Answer: B Explanation: ipcRenderer.invoke triggers a handler in the main process and returns a promise with the result, while send simply fires an event without awaiting a reply.
Question 9. Which API enables direct communication between two renderer processes without involving the main process? A) ipcRenderer.postMessage B) MessageChannelMain C) MessagePort API via navigator.serviceWorker D) MessagePort objects obtained from new MessageChannel() Answer: D Explanation: new MessageChannel() creates two MessagePort objects that can be transferred to different renderer processes for direct communication.
Question 10. When creating a new BrowserWindow, which option makes the window frameless (no OS chrome)?
A) frame: false B) transparent: true C) titleBarStyle: 'hidden' D) modal: true Answer: A Explanation: Setting frame: false removes the standard window frame, creating a frameless window.
Question 11. Which BrowserWindow option allows the window background to be transparent on macOS and Windows? A) transparent: true B) backgroundColor: '#00000000' C) frame: false D) opacity: 0 Answer: A Explanation: The transparent flag enables a transparent background, allowing underlying desktop content to show through.
Question 12. How can you make a BrowserWindow behave as a modal dialog attached to a parent window? A) Set modal: true and provide a parent reference. B) Use dialog.showMessageBox instead of a window. C) Set alwaysOnTop: true.
Question 15. Which API lets an Electron app place an icon in the system tray (or menu bar on macOS)? A) Menu B) Tray C) Shell D) App Answer: B Explanation: The Tray module manages system‑level tray icons and associated context menus.
Question 16. When using dialog.showOpenDialog, which property allows multiple files to be selected? A) multiple: true B) allowMultiple: true C) properties: ['openFile', 'multiSelections'] D) multiSelect: true Answer: C Explanation: The properties array can include 'multiSelections' to enable selecting multiple files.
Question 17. What does shell.openExternal(url) do? A) Opens the URL inside a new BrowserWindow.
B) Launches the default external application for the URL (e.g., default browser). C) Downloads the URL content to a temporary file. D) Sends the URL to the operating system’s clipboard. Answer: B Explanation: shell.openExternal delegates the URL to the OS, which opens it with the default handler (usually a web browser).
Question 18. Which Node.js module is commonly used within Electron’s main process to read a file’s contents synchronously? A) fs.promises B) fs with readFileSync C) path D) os Answer: B Explanation: The fs module’s readFileSync method reads files synchronously, often used in the main process for quick configuration loading.
Question 19. The powerMonitor module can emit which of the following events? A) onBattery B) suspend and resume C) powerChange D) charging Answer: B
Question 22. What is the purpose of a Content Security Policy (CSP) in an Electron renderer? A) To limit the size of JavaScript files. B) To control which external resources can be loaded, preventing XSS. C) To encrypt all network traffic. D) To disable Node.js integration. Answer: B Explanation: CSP headers define allowed sources for scripts, styles, images, etc., mitigating cross‑site scripting attacks.
Question 23. Enabling the Electron sandbox for a renderer process primarily does what? A) Disables Chromium entirely. B) Runs the renderer in a separate process with limited Node.js access. C) Allows the renderer to use the remote module. D) Grants the renderer full OS privileges. Answer: B Explanation: The sandbox isolates the renderer, restricting Node.js APIs and enhancing security.
Question 24. When handling a permission request for the camera, which event should you listen to? A) session.setPermissionRequestHandler B) app.on('camera-request') C) webContents.on('media-request')
D) navigator.permissions.request in the renderer. Answer: A Explanation: session.setPermissionRequestHandler allows the main process to approve or deny permission requests like camera or microphone.
Question 25. To prevent navigation to untrusted URLs, which webContents method can be used? A) webContents.setWindowOpenHandler B) webContents.on('will-navigate', handler) C) webContents.blockNavigation D) webContents.navigateTo Answer: B Explanation: Listening to the will-navigate event lets you validate or block navigation attempts.
Question 26. Which shortcut opens the Chromium DevTools for a given BrowserWindow? A) Ctrl+Shift+I (Windows/Linux) or Cmd+Option+I (macOS) by default. B) F12 only on Windows. C) Alt+Shift+D. D) There is no default shortcut; you must call win.webContents.openDevTools(). Answer: A Explanation: Electron registers the standard Chrome DevTools shortcut for each window unless overridden.
A) Automatic restart of the app after a crash. B) Collection and upload of crash dumps to a remote server. C) Logging of JavaScript exceptions to the console. D) Disabling all crash dialogs. Answer: B Explanation: crashReporter.start configures Electron to generate minidumps on crashes and optionally send them to a backend.
Question 30. Which build tool allows you to generate installers for Windows, macOS, and Linux from a single configuration? A) Electron Forge B) Electron Builder C) Electron Packager D) npm pack Answer: B Explanation: Electron Builder supports multi‑platform packaging and creates installers for all major OSes with a unified config.
Question 31. Code signing on macOS is required primarily to: A) Enable the app to access the file system. B) Prevent the app from being blocked by Gatekeeper and show a trusted developer name. C) Allow the app to use the remote module. D) Enable automatic updates.
Answer: B Explanation: macOS Gatekeeper checks the code signature; unsigned apps trigger warnings or are blocked.
Question 32. The autoUpdater module in Electron works natively on which platforms without additional configuration? A) Windows only. B) macOS only. C) Both Windows and macOS. D) All platforms including Linux. Answer: C Explanation: autoUpdater uses Squirrel on Windows and Sparkle on macOS; Linux requires third‑party solutions.
Question 33. When a native Node.js module compiled for Windows is used in an Electron app, which tool helps rebuild it for Electron’s specific Node version? A) node-gyp with --target flag. B) electron-rebuild. C) npm rebuild electron. D) electron-packager. Answer: B Explanation: electron-rebuild recompiles native modules against the version of Node bundled with Electron.
Question 36. Which method can be used to prevent a renderer process from loading remote content via loadURL? A) webPreferences: { webSecurity: false } B) webPreferences: { allowRunningInsecureContent: false } C) session.setPermissionCheckHandler returning false for loadURL. D) webPreferences: { nodeIntegration: false } Answer: B Explanation: Setting allowRunningInsecureContent: false (default) blocks loading of insecure (http) resources when the page is served over https.
Question 37. The preload script runs in which context? A) The same isolated context as the renderer’s web page. B) The main process context. C) A privileged context that can access both Node.js and the DOM before the page loads. D) The OS kernel. Answer: C Explanation: Preload scripts execute before any web code, have access to Node.js (if enabled) and can expose safe APIs via contextBridge.
Question 38. Which webPreferences flag disables the ability for the renderer to use eval and similar functions? A) disableEval: true B) sandbox: true
C) javascript: false D) nodeIntegration: false Answer: A Explanation: The disableEval flag (available in recent Electron versions) prevents the use of eval, new Function, and similar dynamic code execution.
Question 39. When a BrowserWindow is created with show: false, how can you later display it once its content is ready? A) win.show() after the ready-to-show event. B) win.visible = true. C) win.focus() automatically shows the window. D) win.setOpacity(1). Answer: A Explanation: Listening for the ready-to-show event and then calling win.show() prevents visual flicker.
Question 40. Which Electron API allows you to capture the screen or a window as an image? A) desktopCapturer b) screenCapture c) BrowserWindow.capturePage d) Both a and c Answer: D
Question 43. When using fs.watchFile, what type of event does it emit? A) change when the file is modified. B) rename when the file is moved. C) update when metadata changes. D) modify only on content change. Answer: A Explanation: fs.watchFile monitors a file and triggers a change event when its stats are altered.
Question 44. Which of the following is NOT a valid globalShortcut accelerator format? A) CommandOrControl+X B) Alt+Shift+F5 C) Ctrl+Alt+ (trailing plus) D) Super+Space Answer: C Explanation: An accelerator cannot end with a dangling plus sign; it must specify a complete key combination.
Question 45. In the session module, what does session.fromPartition('persist:myapp') achieve? A) Creates a temporary session that is cleared on exit.
B) Retrieves a persistent session that stores cookies and cache across launches. C) Shares the default session with the name myapp. D) Disables all caching for the session. Answer: B Explanation: The persist: prefix creates a persistent partition, preserving data between app restarts.
Question 46. Which Chrome DevTools protocol domain is used to monitor memory usage in the main process? A) Memory B) HeapProfiler C) Runtime D) Process Answer: A Explanation: The Memory domain provides methods to take heap snapshots and monitor memory consumption.
Question 47. What is the effect of setting webPreferences: { sandbox: true } on a BrowserWindow? A) The renderer runs in a Chromium sandbox with limited Node.js access. B) The window cannot load any external resources. C) It disables the contextBridge. D) It forces the window to be always on top.