docs: update Quick Start Guide for Electron 12 (#28223)

* docs: Update Quick Start Guide for Electron 12

With `contextIsolation` enabled by default in Electron 12, the Getting Started Guide no longer works as it is written. In order for the basic example to display values from `process.versions`, we need to add a `preload.js` to the example.

* fix: annotate preload code block with a language

* docs: update quick-start Fiddle example to use preload to provide version info

* fix: ensure example files end in a newline

* docs: add security warning to instructions for turning off contextIsolation

Co-authored-by: John Kleinschmidt <jkleinsc@github.com>

* docs: treat preload as an adjective instead of a noun

Co-authored-by: John Kleinschmidt <jkleinsc@github.com>

Co-authored-by: John Kleinschmidt <jkleinsc@github.com>
This commit is contained in:
Will Anderson 2021-03-16 16:45:38 -07:00 committed by GitHub
parent 80f89a3472
commit b6ff12ef7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 71 additions and 28 deletions

View file

@ -8,9 +8,9 @@
<body>
<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>.
We are using Node.js <span id="node-version"></span>,
Chromium <span id="chrome-version"></span>,
and Electron <span id="electron-version"></span>.
</p>
</body>
</html>

View file

@ -1,19 +1,27 @@
const { app, BrowserWindow } = require('electron')
const path = require('path')
function createWindow () {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
preload: path.join(__dirname, 'preload.js')
}
})
win.loadFile('index.html')
}
app.whenReady().then(createWindow)
app.whenReady().then(() => {
createWindow()
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
@ -21,8 +29,3 @@ app.on('window-all-closed', () => {
}
})
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})

View file

@ -0,0 +1,11 @@
window.addEventListener('DOMContentLoaded', () => {
const replaceText = (selector, text) => {
const element = document.getElementById(selector)
if (element) element.innerText = text
}
for (const type of ['chrome', 'node', 'electron']) {
replaceText(`${type}-version`, process.versions[type])
}
})