Merge branch 'update-code-samples' of https://github.com/stevekinney/electron into stevekinney-update-code-samples
This commit is contained in:
commit
969a30fc3b
38 changed files with 258 additions and 252 deletions
|
@ -6,8 +6,8 @@ The following example shows how to quit the application when the last window is
|
||||||
closed:
|
closed:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const app = require('electron').app;
|
const { app } = require('electron');
|
||||||
app.on('window-all-closed', function() {
|
app.on('window-all-closed', () => {
|
||||||
app.quit();
|
app.quit();
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
@ -237,7 +237,7 @@ should prevent the default behavior with `event.preventDefault()` and call
|
||||||
`callback(username, password)` with the credentials.
|
`callback(username, password)` with the credentials.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
app.on('login', function(event, webContents, request, authInfo, callback) {
|
app.on('login', (event, webContents, request, authInfo, callback) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
callback('username', 'secret');
|
callback('username', 'secret');
|
||||||
})
|
})
|
||||||
|
@ -481,9 +481,9 @@ An example of activating the window of primary instance when a second instance
|
||||||
starts:
|
starts:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var myWindow = null;
|
let myWindow = null;
|
||||||
|
|
||||||
var shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory) {
|
const shouldQuit = app.makeSingleInstance((commandLine, workingDirectory) => {
|
||||||
// Someone tried to run a second instance, we should focus our window.
|
// Someone tried to run a second instance, we should focus our window.
|
||||||
if (myWindow) {
|
if (myWindow) {
|
||||||
if (myWindow.isMinimized()) myWindow.restore();
|
if (myWindow.isMinimized()) myWindow.restore();
|
||||||
|
@ -497,7 +497,7 @@ if (shouldQuit) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create myWindow, load the rest of the app, etc...
|
// Create myWindow, load the rest of the app, etc...
|
||||||
app.on('ready', function() {
|
app.on('ready', () => {
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -4,13 +4,13 @@
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// In the main process.
|
// In the main process.
|
||||||
const BrowserWindow = require('electron').BrowserWindow;
|
const { BrowserWindow } = require('electron');
|
||||||
|
|
||||||
// Or in the renderer process.
|
// Or in the renderer process.
|
||||||
const BrowserWindow = require('electron').remote.BrowserWindow;
|
const { BrowserWindow } = require('electron').remote;
|
||||||
|
|
||||||
var win = new BrowserWindow({ width: 800, height: 600, show: false });
|
let win = new BrowserWindow({ width: 800, height: 600, show: false });
|
||||||
win.on('closed', function() {
|
win.on('closed', () => {
|
||||||
win = null;
|
win = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -315,7 +315,7 @@ Commands are lowercased with underscores replaced with hyphens and the
|
||||||
e.g. `APPCOMMAND_BROWSER_BACKWARD` is emitted as `browser-backward`.
|
e.g. `APPCOMMAND_BROWSER_BACKWARD` is emitted as `browser-backward`.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
someWindow.on('app-command', function(e, cmd) {
|
someWindow.on('app-command', (e, cmd) => {
|
||||||
// Navigate the window back when the user hits their mouse back button
|
// Navigate the window back when the user hits their mouse back button
|
||||||
if (cmd === 'browser-backward' && someWindow.webContents.canGoBack()) {
|
if (cmd === 'browser-backward' && someWindow.webContents.canGoBack()) {
|
||||||
someWindow.webContents.goBack();
|
someWindow.webContents.goBack();
|
||||||
|
|
|
@ -7,11 +7,11 @@ your app's main script before the [ready][ready] event of the [app][app] module
|
||||||
is emitted:
|
is emitted:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const app = require('electron').app;
|
const { app } = require('electron');
|
||||||
app.commandLine.appendSwitch('remote-debugging-port', '8315');
|
app.commandLine.appendSwitch('remote-debugging-port', '8315');
|
||||||
app.commandLine.appendSwitch('host-rules', 'MAP * 127.0.0.1');
|
app.commandLine.appendSwitch('host-rules', 'MAP * 127.0.0.1');
|
||||||
|
|
||||||
app.on('ready', function() {
|
app.on('ready', () => {
|
||||||
// Your code here
|
// Your code here
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
The following example shows how to write a string to the clipboard:
|
The following example shows how to write a string to the clipboard:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const clipboard = require('electron').clipboard;
|
const { clipboard } = require('electron');
|
||||||
clipboard.writeText('Example String');
|
clipboard.writeText('Example String');
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ This module does not include a web interface so you need to open
|
||||||
result.
|
result.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const contentTracing = require('electron').contentTracing;
|
const { contentTracing } = require('electron');
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
categoryFilter: '*',
|
categoryFilter: '*',
|
||||||
|
@ -18,8 +18,8 @@ const options = {
|
||||||
contentTracing.startRecording(options, function() {
|
contentTracing.startRecording(options, function() {
|
||||||
console.log('Tracing started');
|
console.log('Tracing started');
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(() => {
|
||||||
contentTracing.stopRecording('', function(path) {
|
contentTracing.stopRecording('', (path) => {
|
||||||
console.log('Tracing data recorded to ' + path);
|
console.log('Tracing data recorded to ' + path);
|
||||||
});
|
});
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
|
|
@ -6,7 +6,7 @@ The following is an example of automatically submitting a crash report to a
|
||||||
remote server:
|
remote server:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const crashReporter = require('electron').crashReporter;
|
const { crashReporter } = require('electron');
|
||||||
|
|
||||||
crashReporter.start({
|
crashReporter.start({
|
||||||
productName: 'YourName',
|
productName: 'YourName',
|
||||||
|
|
|
@ -5,9 +5,9 @@ microphone, camera, or screen.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// In the renderer process.
|
// In the renderer process.
|
||||||
var desktopCapturer = require('electron').desktopCapturer;
|
var { desktopCapturer } = require('electron');
|
||||||
|
|
||||||
desktopCapturer.getSources({types: ['window', 'screen']}, function(error, sources) {
|
desktopCapturer.getSources({types: ['window', 'screen']}, (error, sources) => {
|
||||||
if (error) throw error;
|
if (error) throw error;
|
||||||
for (var i = 0; i < sources.length; ++i) {
|
for (var i = 0; i < sources.length; ++i) {
|
||||||
if (sources[i].name == "Electron") {
|
if (sources[i].name == "Electron") {
|
||||||
|
|
|
@ -6,7 +6,7 @@ An example of showing a dialog to select multiple files and directories:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var win = ...; // BrowserWindow in which to show the dialog
|
var win = ...; // BrowserWindow in which to show the dialog
|
||||||
const dialog = require('electron').dialog;
|
const { dialog } = require('electron');
|
||||||
console.log(dialog.showOpenDialog({ properties: [ 'openFile', 'openDirectory', 'multiSelections' ]}));
|
console.log(dialog.showOpenDialog({ properties: [ 'openFile', 'openDirectory', 'multiSelections' ]}));
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ The Dialog is opened from Electron's main thread. If you want to use the dialog
|
||||||
object from a renderer process, remember to access it using the remote:
|
object from a renderer process, remember to access it using the remote:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const dialog = require('electron').remote.dialog;
|
const { dialog } = require('electron').remote;
|
||||||
```
|
```
|
||||||
|
|
||||||
## Methods
|
## Methods
|
||||||
|
|
|
@ -8,17 +8,17 @@ control the download item.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// In the main process.
|
// In the main process.
|
||||||
win.webContents.session.on('will-download', function(event, item, webContents) {
|
win.webContents.session.on('will-download', (event, item, webContents) => {
|
||||||
// Set the save path, making Electron not to prompt a save dialog.
|
// Set the save path, making Electron not to prompt a save dialog.
|
||||||
item.setSavePath('/tmp/save.pdf');
|
item.setSavePath('/tmp/save.pdf');
|
||||||
console.log(item.getMimeType());
|
console.log(item.getMimeType());
|
||||||
console.log(item.getFilename());
|
console.log(item.getFilename());
|
||||||
console.log(item.getTotalBytes());
|
console.log(item.getTotalBytes());
|
||||||
item.on('updated', function() {
|
item.on('updated', () => {
|
||||||
console.log('Received bytes: ' + item.getReceivedBytes());
|
console.log('Received bytes: ' + item.getReceivedBytes());
|
||||||
});
|
});
|
||||||
item.on('done', function(e, state) {
|
item.on('done', (e, state) => {
|
||||||
if (state == "completed") {
|
if (state === "completed") {
|
||||||
console.log("Download successfully");
|
console.log("Download successfully");
|
||||||
} else {
|
} else {
|
||||||
console.log("Download is cancelled or interrupted that can't be resumed");
|
console.log("Download is cancelled or interrupted that can't be resumed");
|
||||||
|
|
|
@ -15,16 +15,16 @@ Example on getting a real path from a dragged-onto-the-app file:
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var holder = document.getElementById('holder');
|
const holder = document.getElementById('holder');
|
||||||
holder.ondragover = function () {
|
holder.ondragover = () => {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
holder.ondragleave = holder.ondragend = function () {
|
holder.ondragleave = holder.ondragend = () => {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
holder.ondrop = function (e) {
|
holder.ondrop = (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var file = e.dataTransfer.files[0];
|
const file = e.dataTransfer.files[0];
|
||||||
console.log('File you dragged here is', file.path);
|
console.log('File you dragged here is', file.path);
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,8 +14,8 @@ To create a frameless window, you need to set `frame` to `false` in
|
||||||
|
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const BrowserWindow = require('electron').BrowserWindow;
|
const { BrowserWindow } = require('electron');
|
||||||
var win = new BrowserWindow({ width: 800, height: 600, frame: false });
|
let win = new BrowserWindow({ width: 800, height: 600, frame: false });
|
||||||
```
|
```
|
||||||
|
|
||||||
### Alternatives on OS X
|
### Alternatives on OS X
|
||||||
|
@ -28,7 +28,7 @@ the window controls ("traffic lights") for standard window actions.
|
||||||
You can do so by specifying the new `titleBarStyle` option:
|
You can do so by specifying the new `titleBarStyle` option:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var win = new BrowserWindow({ 'titleBarStyle': 'hidden' });
|
let win = new BrowserWindow({ 'titleBarStyle': 'hidden' });
|
||||||
```
|
```
|
||||||
|
|
||||||
## Transparent window
|
## Transparent window
|
||||||
|
@ -37,7 +37,7 @@ By setting the `transparent` option to `true`, you can also make the frameless
|
||||||
window transparent:
|
window transparent:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var win = new BrowserWindow({ transparent: true, frame: false });
|
let win = new BrowserWindow({ transparent: true, frame: false });
|
||||||
```
|
```
|
||||||
|
|
||||||
### Limitations
|
### Limitations
|
||||||
|
|
|
@ -12,12 +12,11 @@ event of the app module is emitted.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const electron = require('electron');
|
const electron = require('electron');
|
||||||
const app = electron.app;
|
const { app, globalShortcut } = electron;
|
||||||
const globalShortcut = electron.globalShortcut;
|
|
||||||
|
|
||||||
app.on('ready', function() {
|
app.on('ready', () => {
|
||||||
// Register a 'CommandOrControl+X' shortcut listener.
|
// Register a 'CommandOrControl+X' shortcut listener.
|
||||||
var ret = globalShortcut.register('CommandOrControl+X', function() {
|
const ret = globalShortcut.register('CommandOrControl+X', function() {
|
||||||
console.log('CommandOrControl+X is pressed');
|
console.log('CommandOrControl+X is pressed');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -29,7 +28,7 @@ app.on('ready', function() {
|
||||||
console.log(globalShortcut.isRegistered('CommandOrControl+X'));
|
console.log(globalShortcut.isRegistered('CommandOrControl+X'));
|
||||||
});
|
});
|
||||||
|
|
||||||
app.on('will-quit', function() {
|
app.on('will-quit', () => {
|
||||||
// Unregister a shortcut.
|
// Unregister a shortcut.
|
||||||
globalShortcut.unregister('CommandOrControl+X');
|
globalShortcut.unregister('CommandOrControl+X');
|
||||||
|
|
||||||
|
|
|
@ -23,13 +23,13 @@ processes:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// In main process.
|
// In main process.
|
||||||
const ipcMain = require('electron').ipcMain;
|
const { ipcMain } = require('electron');
|
||||||
ipcMain.on('asynchronous-message', function(event, arg) {
|
ipcMain.on('asynchronous-message', (event, arg) => {
|
||||||
console.log(arg); // prints "ping"
|
console.log(arg); // prints "ping"
|
||||||
event.sender.send('asynchronous-reply', 'pong');
|
event.sender.send('asynchronous-reply', 'pong');
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on('synchronous-message', function(event, arg) {
|
ipcMain.on('synchronous-message', (event, arg) => {
|
||||||
console.log(arg); // prints "ping"
|
console.log(arg); // prints "ping"
|
||||||
event.returnValue = 'pong';
|
event.returnValue = 'pong';
|
||||||
});
|
});
|
||||||
|
@ -37,10 +37,10 @@ ipcMain.on('synchronous-message', function(event, arg) {
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// In renderer process (web page).
|
// In renderer process (web page).
|
||||||
const ipcRenderer = require('electron').ipcRenderer;
|
const { ipcRenderer } = require('electron');
|
||||||
console.log(ipcRenderer.sendSync('synchronous-message', 'ping')); // prints "pong"
|
console.log(ipcRenderer.sendSync('synchronous-message', 'ping')); // prints "pong"
|
||||||
|
|
||||||
ipcRenderer.on('asynchronous-reply', function(event, arg) {
|
ipcRenderer.on('asynchronous-reply', (event, arg) => {
|
||||||
console.log(arg); // prints "pong"
|
console.log(arg); // prints "pong"
|
||||||
});
|
});
|
||||||
ipcRenderer.send('asynchronous-message', 'ping');
|
ipcRenderer.send('asynchronous-message', 'ping');
|
||||||
|
|
|
@ -15,16 +15,14 @@ the user right clicks the page:
|
||||||
```html
|
```html
|
||||||
<!-- index.html -->
|
<!-- index.html -->
|
||||||
<script>
|
<script>
|
||||||
const remote = require('electron').remote;
|
const { Menu, MenuItem } = require('electron').remote;
|
||||||
const Menu = remote.Menu;
|
|
||||||
const MenuItem = remote.MenuItem;
|
|
||||||
|
|
||||||
var menu = new Menu();
|
const menu = new Menu();
|
||||||
menu.append(new MenuItem({ label: 'MenuItem1', click: function() { console.log('item 1 clicked'); } }));
|
menu.append(new MenuItem({ label: 'MenuItem1', click: () => { console.log('item 1 clicked'); } }));
|
||||||
menu.append(new MenuItem({ type: 'separator' }));
|
menu.append(new MenuItem({ type: 'separator' }));
|
||||||
menu.append(new MenuItem({ label: 'MenuItem2', type: 'checkbox', checked: true }));
|
menu.append(new MenuItem({ label: 'MenuItem2', type: 'checkbox', checked: true }));
|
||||||
|
|
||||||
window.addEventListener('contextmenu', function (e) {
|
window.addEventListener('contextmenu', (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
menu.popup(remote.getCurrentWindow());
|
menu.popup(remote.getCurrentWindow());
|
||||||
}, false);
|
}, false);
|
||||||
|
@ -35,7 +33,7 @@ An example of creating the application menu in the render process with the
|
||||||
simple template API:
|
simple template API:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var template = [
|
const template = [
|
||||||
{
|
{
|
||||||
label: 'Edit',
|
label: 'Edit',
|
||||||
submenu: [
|
submenu: [
|
||||||
|
@ -80,33 +78,32 @@ var template = [
|
||||||
{
|
{
|
||||||
label: 'Reload',
|
label: 'Reload',
|
||||||
accelerator: 'CmdOrCtrl+R',
|
accelerator: 'CmdOrCtrl+R',
|
||||||
click: function(item, focusedWindow) {
|
click: (item, focusedWindow) => {
|
||||||
if (focusedWindow)
|
if (focusedWindow) focusedWindow.reload();
|
||||||
focusedWindow.reload();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Toggle Full Screen',
|
label: 'Toggle Full Screen',
|
||||||
accelerator: (function() {
|
accelerator: (() => {
|
||||||
if (process.platform == 'darwin')
|
if (process.platform === 'darwin')
|
||||||
return 'Ctrl+Command+F';
|
return 'Ctrl+Command+F';
|
||||||
else
|
else
|
||||||
return 'F11';
|
return 'F11';
|
||||||
})(),
|
})(),
|
||||||
click: function(item, focusedWindow) {
|
click: (item, focusedWindow) => {
|
||||||
if (focusedWindow)
|
if (focusedWindow)
|
||||||
focusedWindow.setFullScreen(!focusedWindow.isFullScreen());
|
focusedWindow.setFullScreen(!focusedWindow.isFullScreen());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Toggle Developer Tools',
|
label: 'Toggle Developer Tools',
|
||||||
accelerator: (function() {
|
accelerator: (() => {
|
||||||
if (process.platform == 'darwin')
|
if (process.platform == 'darwin')
|
||||||
return 'Alt+Command+I';
|
return 'Alt+Command+I';
|
||||||
else
|
else
|
||||||
return 'Ctrl+Shift+I';
|
return 'Ctrl+Shift+I';
|
||||||
})(),
|
})(),
|
||||||
click: function(item, focusedWindow) {
|
click: (item, focusedWindow) => {
|
||||||
if (focusedWindow)
|
if (focusedWindow)
|
||||||
focusedWindow.webContents.toggleDevTools();
|
focusedWindow.webContents.toggleDevTools();
|
||||||
}
|
}
|
||||||
|
@ -135,14 +132,14 @@ var template = [
|
||||||
submenu: [
|
submenu: [
|
||||||
{
|
{
|
||||||
label: 'Learn More',
|
label: 'Learn More',
|
||||||
click: function() { require('electron').shell.openExternal('http://electron.atom.io') }
|
click: () => { require('electron').shell.openExternal('http://electron.atom.io') }
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
if (process.platform == 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
var name = require('electron').remote.app.getName();
|
const name = require('electron').remote.app.getName();
|
||||||
template.unshift({
|
template.unshift({
|
||||||
label: name,
|
label: name,
|
||||||
submenu: [
|
submenu: [
|
||||||
|
@ -181,7 +178,7 @@ if (process.platform == 'darwin') {
|
||||||
{
|
{
|
||||||
label: 'Quit',
|
label: 'Quit',
|
||||||
accelerator: 'Command+Q',
|
accelerator: 'Command+Q',
|
||||||
click: function() { app.quit(); }
|
click: () => { app.quit(); }
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
@ -197,7 +194,7 @@ if (process.platform == 'darwin') {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var menu = Menu.buildFromTemplate(template);
|
const menu = Menu.buildFromTemplate(template);
|
||||||
Menu.setApplicationMenu(menu);
|
Menu.setApplicationMenu(menu);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -9,15 +9,15 @@ For example, when creating a tray or setting a window's icon, you can pass an
|
||||||
image file path as a `String`:
|
image file path as a `String`:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var appIcon = new Tray('/Users/somebody/images/icon.png');
|
const appIcon = new Tray('/Users/somebody/images/icon.png');
|
||||||
var window = new BrowserWindow({icon: '/Users/somebody/images/window.png'});
|
let window = new BrowserWindow({icon: '/Users/somebody/images/window.png'});
|
||||||
```
|
```
|
||||||
|
|
||||||
Or read the image from the clipboard which returns a `nativeImage`:
|
Or read the image from the clipboard which returns a `nativeImage`:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var image = clipboard.readImage();
|
const image = clipboard.readImage();
|
||||||
var appIcon = new Tray(image);
|
const appIcon = new Tray(image);
|
||||||
```
|
```
|
||||||
|
|
||||||
## Supported Formats
|
## Supported Formats
|
||||||
|
|
|
@ -8,8 +8,8 @@ event of the `app` module is emitted.
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
app.on('ready', function() {
|
app.on('ready', () => {
|
||||||
require('electron').powerMonitor.on('suspend', function() {
|
require('electron').powerMonitor.on('suspend', () => {
|
||||||
console.log('The system is going to sleep');
|
console.log('The system is going to sleep');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,9 +5,9 @@
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const powerSaveBlocker = require('electron').powerSaveBlocker;
|
const { powerSaveBlocker } = require('electron');
|
||||||
|
|
||||||
var id = powerSaveBlocker.start('prevent-display-sleep');
|
const id = powerSaveBlocker.start('prevent-display-sleep');
|
||||||
console.log(powerSaveBlocker.isStarted(id));
|
console.log(powerSaveBlocker.isStarted(id));
|
||||||
|
|
||||||
powerSaveBlocker.stop(id);
|
powerSaveBlocker.stop(id);
|
||||||
|
|
|
@ -27,8 +27,8 @@ the global scope when node integration is turned off:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// preload.js
|
// preload.js
|
||||||
var _setImmediate = setImmediate;
|
const _setImmediate = setImmediate;
|
||||||
var _clearImmediate = clearImmediate;
|
const _clearImmediate = clearImmediate;
|
||||||
process.once('loaded', function() {
|
process.once('loaded', function() {
|
||||||
global.setImmediate = _setImmediate;
|
global.setImmediate = _setImmediate;
|
||||||
global.clearImmediate = _clearImmediate;
|
global.clearImmediate = _clearImmediate;
|
||||||
|
|
|
@ -7,13 +7,13 @@ An example of implementing a protocol that has the same effect as the
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const electron = require('electron');
|
const electron = require('electron');
|
||||||
const app = electron.app;
|
const { app } = electron;
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
app.on('ready', function() {
|
app.on('ready', function() {
|
||||||
var protocol = electron.protocol;
|
const { protocol } = electron;
|
||||||
protocol.registerFileProtocol('atom', function(request, callback) {
|
protocol.registerFileProtocol('atom', function(request, callback) {
|
||||||
var url = request.url.substr(7);
|
const url = request.url.substr(7);
|
||||||
callback({path: path.normalize(__dirname + '/' + url)});
|
callback({path: path.normalize(__dirname + '/' + url)});
|
||||||
}, function (error) {
|
}, function (error) {
|
||||||
if (error)
|
if (error)
|
||||||
|
@ -95,9 +95,9 @@ should be called with either a `Buffer` object or an object that has the `data`,
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
protocol.registerBufferProtocol('atom', function(request, callback) {
|
protocol.registerBufferProtocol('atom', (request, callback) => {
|
||||||
callback({mimeType: 'text/html', data: new Buffer('<h5>Response</h5>')});
|
callback({mimeType: 'text/html', data: new Buffer('<h5>Response</h5>')});
|
||||||
}, function (error) {
|
}, (error) => {
|
||||||
if (error)
|
if (error)
|
||||||
console.error('Failed to register protocol')
|
console.error('Failed to register protocol')
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,8 +14,7 @@ similar to Java's [RMI][rmi]. An example of creating a browser window from a
|
||||||
renderer process:
|
renderer process:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const remote = require('electron').remote;
|
const { BrowserWindow } = require('electron').remote;
|
||||||
const BrowserWindow = remote.BrowserWindow;
|
|
||||||
|
|
||||||
var win = new BrowserWindow({ width: 800, height: 600 });
|
var win = new BrowserWindow({ width: 800, height: 600 });
|
||||||
win.loadURL('https://github.com');
|
win.loadURL('https://github.com');
|
||||||
|
@ -69,26 +68,22 @@ For instance you can't use a function from the renderer process in an
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// main process mapNumbers.js
|
// main process mapNumbers.js
|
||||||
exports.withRendererCallback = function(mapper) {
|
exports.withRendererCallback = (mapper) => {
|
||||||
return [1,2,3].map(mapper);
|
return [1,2,3].map(mapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.withLocalCallback = function() {
|
exports.withLocalCallback = () => {
|
||||||
return exports.mapNumbers(function(x) {
|
return exports.mapNumbers(x => x + 1);
|
||||||
return x + 1;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// renderer process
|
// renderer process
|
||||||
var mapNumbers = require("remote").require("./mapNumbers");
|
const mapNumbers = require("remote").require("./mapNumbers");
|
||||||
|
|
||||||
var withRendererCb = mapNumbers.withRendererCallback(function(x) {
|
const withRendererCb = mapNumbers.withRendererCallback(x => x + 1);
|
||||||
return x + 1;
|
|
||||||
})
|
|
||||||
|
|
||||||
var withLocalCb = mapNumbers.withLocalCallback()
|
const withLocalCb = mapNumbers.withLocalCallback()
|
||||||
|
|
||||||
console.log(withRendererCb, withLocalCb) // [true, true, true], [2, 3, 4]
|
console.log(withRendererCb, withLocalCb) // [true, true, true], [2, 3, 4]
|
||||||
```
|
```
|
||||||
|
@ -104,7 +99,7 @@ For example, the following code seems innocent at first glance. It installs a
|
||||||
callback for the `close` event on a remote object:
|
callback for the `close` event on a remote object:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
remote.getCurrentWindow().on('close', function() {
|
remote.getCurrentWindow().on('close', () => {
|
||||||
// blabla...
|
// blabla...
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
|
@ -14,15 +14,13 @@ An example of creating a window that fills the whole screen:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const electron = require('electron');
|
const electron = require('electron');
|
||||||
const app = electron.app;
|
const { app, BrowserWindow } = electron;
|
||||||
const BrowserWindow = electron.BrowserWindow;
|
|
||||||
|
|
||||||
var mainWindow;
|
let mainWindow;
|
||||||
|
|
||||||
app.on('ready', function() {
|
app.on('ready', () => {
|
||||||
var electronScreen = electron.screen;
|
const { width, height } = electron.screen.getPrimaryDisplay().workAreaSize;
|
||||||
var size = electronScreen.getPrimaryDisplay().workAreaSize;
|
mainWindow = new BrowserWindow({ width, height });
|
||||||
mainWindow = new BrowserWindow({ width: size.width, height: size.height });
|
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -30,16 +28,15 @@ Another example of creating a window in the external display:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const electron = require('electron');
|
const electron = require('electron');
|
||||||
const app = electron.app;
|
const { app, BrowserWindow } = electron;
|
||||||
const BrowserWindow = electron.BrowserWindow;
|
|
||||||
|
|
||||||
var mainWindow;
|
let mainWindow;
|
||||||
|
|
||||||
app.on('ready', function() {
|
app.on('ready', () => {
|
||||||
var electronScreen = electron.screen;
|
var electronScreen = electron.screen;
|
||||||
var displays = electronScreen.getAllDisplays();
|
var displays = electronScreen.getAllDisplays();
|
||||||
var externalDisplay = null;
|
var externalDisplay = null;
|
||||||
for (var i in displays) {
|
for (let i in displays) {
|
||||||
if (displays[i].bounds.x != 0 || displays[i].bounds.y != 0) {
|
if (displays[i].bounds.x != 0 || displays[i].bounds.y != 0) {
|
||||||
externalDisplay = displays[i];
|
externalDisplay = displays[i];
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -9,12 +9,12 @@ property of [`webContents`](web-contents.md) which is a property of
|
||||||
[`BrowserWindow`](browser-window.md).
|
[`BrowserWindow`](browser-window.md).
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const BrowserWindow = require('electron').BrowserWindow;
|
const { BrowserWindow } = require('electron');
|
||||||
|
|
||||||
var win = new BrowserWindow({ width: 800, height: 600 });
|
let win = new BrowserWindow({ width: 800, height: 600 });
|
||||||
win.loadURL("http://github.com");
|
win.loadURL("http://github.com");
|
||||||
|
|
||||||
var ses = win.webContents.session;
|
const ses = win.webContents.session;
|
||||||
```
|
```
|
||||||
|
|
||||||
## Methods
|
## Methods
|
||||||
|
@ -47,7 +47,7 @@ You can create a `Session` object in the `session` module:
|
||||||
```javascript
|
```javascript
|
||||||
const session = require('electron').session;
|
const session = require('electron').session;
|
||||||
|
|
||||||
var ses = session.fromPartition('persist:name');
|
const ses = session.fromPartition('persist:name');
|
||||||
```
|
```
|
||||||
|
|
||||||
### Instance Events
|
### Instance Events
|
||||||
|
@ -66,9 +66,9 @@ Calling `event.preventDefault()` will cancel the download and `item` will not be
|
||||||
available from next tick of the process.
|
available from next tick of the process.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
session.defaultSession.on('will-download', function(event, item, webContents) {
|
session.defaultSession.on('will-download', (event, item, webContents) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
require('request')(item.getURL(), function(data) {
|
require('request')(item.getURL(), (data) => {
|
||||||
require('fs').writeFileSync('/somewhere', data);
|
require('fs').writeFileSync('/somewhere', data);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -84,19 +84,19 @@ The `cookies` gives you ability to query and modify cookies. For example:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// Query all cookies.
|
// Query all cookies.
|
||||||
session.defaultSession.cookies.get({}, function(error, cookies) {
|
session.defaultSession.cookies.get({}, (error, cookies) => {
|
||||||
console.log(cookies);
|
console.log(cookies);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Query all cookies associated with a specific url.
|
// Query all cookies associated with a specific url.
|
||||||
session.defaultSession.cookies.get({ url : "http://www.github.com" }, function(error, cookies) {
|
session.defaultSession.cookies.get({ url : "http://www.github.com" }, (error, cookies) => {
|
||||||
console.log(cookies);
|
console.log(cookies);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set a cookie with the given cookie data;
|
// Set a cookie with the given cookie data;
|
||||||
// may overwrite equivalent cookies if they exist.
|
// may overwrite equivalent cookies if they exist.
|
||||||
var cookie = { url : "http://www.github.com", name : "dummy_name", value : "dummy" };
|
const cookie = { url : "http://www.github.com", name : "dummy_name", value : "dummy" };
|
||||||
session.defaultSession.cookies.set(cookie, function(error) {
|
session.defaultSession.cookies.set(cookie, (error) => {
|
||||||
if (error)
|
if (error)
|
||||||
console.error(error);
|
console.error(error);
|
||||||
});
|
});
|
||||||
|
@ -285,8 +285,8 @@ Calling `setCertificateVerifyProc(null)` will revert back to default certificate
|
||||||
verify proc.
|
verify proc.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
myWindow.webContents.session.setCertificateVerifyProc(function(hostname, cert, callback) {
|
myWindow.webContents.session.setCertificateVerifyProc((hostname, cert, callback) => {
|
||||||
if (hostname == 'github.com')
|
if (hostname === 'github.com')
|
||||||
callback(true);
|
callback(true);
|
||||||
else
|
else
|
||||||
callback(false);
|
callback(false);
|
||||||
|
@ -305,9 +305,9 @@ Sets the handler which can be used to respond to permission requests for the `se
|
||||||
Calling `callback(true)` will allow the permission and `callback(false)` will reject it.
|
Calling `callback(true)` will allow the permission and `callback(false)` will reject it.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
session.fromPartition(partition).setPermissionRequestHandler(function(webContents, permission, callback) {
|
session.fromPartition(partition).setPermissionRequestHandler((webContents, permission, callback) => {
|
||||||
if (webContents.getURL() === host) {
|
if (webContents.getURL() === host) {
|
||||||
if (permission == "notifications") {
|
if (permission === "notifications") {
|
||||||
callback(false); // denied.
|
callback(false); // denied.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -342,11 +342,11 @@ called with an `response` object when `listener` has done its work.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// Modify the user agent for all requests to the following urls.
|
// Modify the user agent for all requests to the following urls.
|
||||||
var filter = {
|
const filter = {
|
||||||
urls: ["https://*.github.com/*", "*://electron.github.io"]
|
urls: ["https://*.github.com/*", "*://electron.github.io"]
|
||||||
};
|
};
|
||||||
|
|
||||||
session.defaultSession.webRequest.onBeforeSendHeaders(filter, function(details, callback) {
|
session.defaultSession.webRequest.onBeforeSendHeaders(filter, (details, callback) => {
|
||||||
details.requestHeaders['User-Agent'] = "MyAgent";
|
details.requestHeaders['User-Agent'] = "MyAgent";
|
||||||
callback({cancel: false, requestHeaders: details.requestHeaders});
|
callback({cancel: false, requestHeaders: details.requestHeaders});
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,7 +7,7 @@ The `shell` module provides functions related to desktop integration.
|
||||||
An example of opening a URL in the user's default browser:
|
An example of opening a URL in the user's default browser:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const shell = require('electron').shell;
|
const { shell } = require('electron');
|
||||||
|
|
||||||
shell.openExternal('https://github.com');
|
shell.openExternal('https://github.com');
|
||||||
```
|
```
|
||||||
|
|
|
@ -19,13 +19,11 @@ scripts to be able to use those modules.
|
||||||
The main process script is just like a normal Node.js script:
|
The main process script is just like a normal Node.js script:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const electron = require('electron');
|
const { app, BrowserWindow } = require('electron');
|
||||||
const app = electron.app;
|
|
||||||
const BrowserWindow = electron.BrowserWindow;
|
|
||||||
|
|
||||||
var window = null;
|
let window = null;
|
||||||
|
|
||||||
app.on('ready', function() {
|
app.on('ready', () => {
|
||||||
window = new BrowserWindow({width: 800, height: 600});
|
window = new BrowserWindow({width: 800, height: 600});
|
||||||
window.loadURL('https://github.com');
|
window.loadURL('https://github.com');
|
||||||
});
|
});
|
||||||
|
@ -39,7 +37,7 @@ extra ability to use node modules:
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<script>
|
<script>
|
||||||
const remote = require('electron').remote;
|
const { remote } = require('electron');
|
||||||
console.log(remote.app.getVersion());
|
console.log(remote.app.getVersion());
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
@ -50,16 +48,29 @@ To run your app, read [Run your app](../tutorial/quick-start.md#run-your-app).
|
||||||
|
|
||||||
## Destructuring assignment
|
## Destructuring assignment
|
||||||
|
|
||||||
If you are using CoffeeScript or Babel, you can also use
|
As of 0.37, you can use
|
||||||
[destructuring assignment][destructuring-assignment] to make it easier to use
|
[destructuring assignment][destructuring-assignment] to make it easier to use
|
||||||
built-in modules:
|
built-in modules.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const {app, BrowserWindow} = require('electron')
|
const { app, BrowserWindow } = require('electron');
|
||||||
```
|
```
|
||||||
|
|
||||||
However if you are using plain JavaScript, you have to wait until Chrome fully
|
If you need the entire `electron` module, you can require it and then using
|
||||||
supports ES6.
|
destructuring to access the individual modules from `electron`.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const electron = require('electron');
|
||||||
|
const { app, BrowserWindow } = electron;
|
||||||
|
```
|
||||||
|
|
||||||
|
This is equivalent to the following code:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const electron = require('electron');
|
||||||
|
const app = electron.app;
|
||||||
|
const BrowserWindow = electron.BrowserWindow;
|
||||||
|
```
|
||||||
|
|
||||||
## Disable old styles of using built-in modules
|
## Disable old styles of using built-in modules
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ An example of using it to determine if you should create a transparent window or
|
||||||
not (transparent windows won't work correctly when DWM composition is disabled):
|
not (transparent windows won't work correctly when DWM composition is disabled):
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
let browserOptions = {width: 1000, height: 800};
|
let browserOptions = { width: 1000, height: 800 };
|
||||||
|
|
||||||
// Make the window transparent only if the platform supports it.
|
// Make the window transparent only if the platform supports it.
|
||||||
if (process.platform !== 'win32' || systemPreferences.isAeroGlassEnabled()) {
|
if (process.platform !== 'win32' || systemPreferences.isAeroGlassEnabled()) {
|
||||||
|
|
|
@ -8,10 +8,10 @@ const app = electron.app;
|
||||||
const Menu = electron.Menu;
|
const Menu = electron.Menu;
|
||||||
const Tray = electron.Tray;
|
const Tray = electron.Tray;
|
||||||
|
|
||||||
var appIcon = null;
|
let appIcon = null;
|
||||||
app.on('ready', function(){
|
app.on('ready', () => {
|
||||||
appIcon = new Tray('/path/to/my/icon');
|
appIcon = new Tray('/path/to/my/icon');
|
||||||
var contextMenu = Menu.buildFromTemplate([
|
const contextMenu = Menu.buildFromTemplate([
|
||||||
{ label: 'Item1', type: 'radio' },
|
{ label: 'Item1', type: 'radio' },
|
||||||
{ label: 'Item2', type: 'radio' },
|
{ label: 'Item2', type: 'radio' },
|
||||||
{ label: 'Item3', type: 'radio', checked: true },
|
{ label: 'Item3', type: 'radio', checked: true },
|
||||||
|
@ -20,7 +20,6 @@ app.on('ready', function(){
|
||||||
appIcon.setToolTip('This is my application.');
|
appIcon.setToolTip('This is my application.');
|
||||||
appIcon.setContextMenu(contextMenu);
|
appIcon.setContextMenu(contextMenu);
|
||||||
});
|
});
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
__Platform limitations:__
|
__Platform limitations:__
|
||||||
|
|
|
@ -9,12 +9,12 @@ the [`BrowserWindow`](browser-window.md) object. An example of accessing the
|
||||||
`webContents` object:
|
`webContents` object:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const BrowserWindow = require('electron').BrowserWindow;
|
const { BrowserWindow } = require('electron');
|
||||||
|
|
||||||
var win = new BrowserWindow({width: 800, height: 1500});
|
let win = new BrowserWindow({width: 800, height: 1500});
|
||||||
win.loadURL("http://github.com");
|
win.loadURL("http://github.com");
|
||||||
|
|
||||||
var webContents = win.webContents;
|
let webContents = win.webContents;
|
||||||
```
|
```
|
||||||
|
|
||||||
## Events
|
## Events
|
||||||
|
@ -398,10 +398,10 @@ Initiates a download of the resource at `url` without navigating. The
|
||||||
Returns URL of the current web page.
|
Returns URL of the current web page.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var win = new BrowserWindow({width: 800, height: 600});
|
let win = new BrowserWindow({width: 800, height: 600});
|
||||||
win.loadURL("http://github.com");
|
win.loadURL("http://github.com");
|
||||||
|
|
||||||
var currentURL = win.webContents.getURL();
|
let currentURL = win.webContents.getURL();
|
||||||
```
|
```
|
||||||
|
|
||||||
### `webContents.getTitle()`
|
### `webContents.getTitle()`
|
||||||
|
@ -671,22 +671,22 @@ By default, an empty `options` will be regarded as:
|
||||||
```
|
```
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const BrowserWindow = require('electron').BrowserWindow;
|
const { BrowserWindow } = require('electron');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
var win = new BrowserWindow({width: 800, height: 600});
|
let win = new BrowserWindow({width: 800, height: 600});
|
||||||
win.loadURL("http://github.com");
|
win.loadURL('http://github.com');
|
||||||
|
|
||||||
win.webContents.on("did-finish-load", function() {
|
win.webContents.on('did-finish-load', () => {
|
||||||
// Use default printing options
|
// Use default printing options
|
||||||
win.webContents.printToPDF({}, function(error, data) {
|
win.webContents.printToPDF({}, (error, data) => {
|
||||||
if (error) throw error;
|
if (error) throw error;
|
||||||
fs.writeFile("/tmp/print.pdf", data, function(error) {
|
fs.writeFile('/tmp/print.pdf', data, (error) => {
|
||||||
if (error)
|
if (error)
|
||||||
throw error;
|
throw error;
|
||||||
console.log("Write PDF successfully.");
|
console.log('Write PDF successfully.');
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -761,12 +761,13 @@ An example of sending messages from the main process to the renderer process:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// In the main process.
|
// In the main process.
|
||||||
var window = null;
|
let mainWindow = null;
|
||||||
app.on('ready', function() {
|
|
||||||
window = new BrowserWindow({width: 800, height: 600});
|
app.on('ready', () => {
|
||||||
window.loadURL('file://' + __dirname + '/index.html');
|
mainWindow = new BrowserWindow({width: 800, height: 600});
|
||||||
window.webContents.on('did-finish-load', function() {
|
mainWindow.loadURL(`file://${__dirname}/index.html`);
|
||||||
window.webContents.send('ping', 'whoooooooh!');
|
mainWindow.webContents.on('did-finish-load', () => {
|
||||||
|
mainWindow.webContents.send('ping', 'whoooooooh!');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
@ -776,7 +777,7 @@ app.on('ready', function() {
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<script>
|
<script>
|
||||||
require('electron').ipcRenderer.on('ping', function(event, message) {
|
require('electron').ipcRenderer.on('ping', (event, message) => {
|
||||||
console.log(message); // Prints "whoooooooh!"
|
console.log(message); // Prints "whoooooooh!"
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -892,8 +893,8 @@ Returns true if the process of saving page has been initiated successfully.
|
||||||
```javascript
|
```javascript
|
||||||
win.loadURL('https://github.com');
|
win.loadURL('https://github.com');
|
||||||
|
|
||||||
win.webContents.on('did-finish-load', function() {
|
win.webContents.on('did-finish-load', () => {
|
||||||
win.webContents.savePage('/tmp/test.html', 'HTMLComplete', function(error) {
|
win.webContents.savePage('/tmp/test.html', 'HTMLComplete', (error) => {
|
||||||
if (!error)
|
if (!error)
|
||||||
console.log("Save page successfully");
|
console.log("Save page successfully");
|
||||||
});
|
});
|
||||||
|
@ -930,13 +931,13 @@ try {
|
||||||
console.log("Debugger attach failed : ", err);
|
console.log("Debugger attach failed : ", err);
|
||||||
};
|
};
|
||||||
|
|
||||||
win.webContents.debugger.on('detach', function(event, reason) {
|
win.webContents.debugger.on('detach', (event, reason) => {
|
||||||
console.log("Debugger detached due to : ", reason);
|
console.log("Debugger detached due to : ", reason);
|
||||||
});
|
});
|
||||||
|
|
||||||
win.webContents.debugger.on('message', function(event, method, params) {
|
win.webContents.debugger.on('message', (event, method, params) => {
|
||||||
if (method == "Network.requestWillBeSent") {
|
if (method === "Network.requestWillBeSent") {
|
||||||
if (params.request.url == "https://www.github.com")
|
if (params.request.url === "https://www.github.com")
|
||||||
win.webContents.debugger.detach();
|
win.webContents.debugger.detach();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
An example of zooming current page to 200%.
|
An example of zooming current page to 200%.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var webFrame = require('electron').webFrame;
|
const { webFrame } = require('electron');
|
||||||
|
|
||||||
webFrame.setZoomFactor(2);
|
webFrame.setZoomFactor(2);
|
||||||
```
|
```
|
||||||
|
|
|
@ -31,18 +31,20 @@ and displays a "loading..." message during the load time:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<script>
|
<script>
|
||||||
onload = function() {
|
onload = () => {
|
||||||
var webview = document.getElementById("foo");
|
const webview = document.getElementById('foo');
|
||||||
var indicator = document.querySelector(".indicator");
|
const indicator = document.querySelector('.indicator');
|
||||||
|
|
||||||
var loadstart = function() {
|
const loadstart = () => {
|
||||||
indicator.innerText = "loading...";
|
indicator.innerText = 'loading...';
|
||||||
}
|
}
|
||||||
var loadstop = function() {
|
|
||||||
indicator.innerText = "";
|
const loadstop = () => {
|
||||||
|
indicator.innerText = '';
|
||||||
}
|
}
|
||||||
webview.addEventListener("did-start-loading", loadstart);
|
|
||||||
webview.addEventListener("did-stop-loading", loadstop);
|
webview.addEventListener('did-start-loading', loadstart);
|
||||||
|
webview.addEventListener('did-stop-loading', loadstop);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
```
|
```
|
||||||
|
@ -211,7 +213,7 @@ The `webview` tag has the following methods:
|
||||||
**Example**
|
**Example**
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
webview.addEventListener("dom-ready", function() {
|
webview.addEventListener("dom-ready", () => {
|
||||||
webview.openDevTools();
|
webview.openDevTools();
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
@ -642,10 +644,12 @@ Fired when the guest page attempts to open a new browser window.
|
||||||
The following example code opens the new url in system's default browser.
|
The following example code opens the new url in system's default browser.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
webview.addEventListener('new-window', function(e) {
|
const { shell } = require('electron');
|
||||||
var protocol = require('url').parse(e.url).protocol;
|
|
||||||
|
webview.addEventListener('new-window', (e) => {
|
||||||
|
const protocol = require('url').parse(e.url).protocol;
|
||||||
if (protocol === 'http:' || protocol === 'https:') {
|
if (protocol === 'http:' || protocol === 'https:') {
|
||||||
require('electron').shell.openExternal(e.url);
|
shell.openExternal(e.url);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
@ -700,7 +704,7 @@ The following example code navigates the `webview` to `about:blank` when the
|
||||||
guest attempts to close itself.
|
guest attempts to close itself.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
webview.addEventListener('close', function() {
|
webview.addEventListener('close', () => {
|
||||||
webview.src = 'about:blank';
|
webview.src = 'about:blank';
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
@ -719,7 +723,7 @@ between guest page and embedder page:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// In embedder page.
|
// In embedder page.
|
||||||
webview.addEventListener('ipc-message', function(event) {
|
webview.addEventListener('ipc-message', (event) => {
|
||||||
console.log(event.channel);
|
console.log(event.channel);
|
||||||
// Prints "pong"
|
// Prints "pong"
|
||||||
});
|
});
|
||||||
|
@ -728,8 +732,8 @@ webview.send('ping');
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// In guest page.
|
// In guest page.
|
||||||
var ipcRenderer = require('electron').ipcRenderer;
|
var { ipcRenderer } = require('electron');
|
||||||
ipcRenderer.on('ping', function() {
|
ipcRenderer.on('ping', () => {
|
||||||
ipcRenderer.sendToHost('pong');
|
ipcRenderer.sendToHost('pong');
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
|
@ -60,16 +60,16 @@ If you want a quick fix, you can make the variables global by changing your
|
||||||
code from this:
|
code from this:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
app.on('ready', function() {
|
app.on('ready', () => {
|
||||||
var tray = new Tray('/path/to/icon.png');
|
const tray = new Tray('/path/to/icon.png');
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
to this:
|
to this:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var tray = null;
|
let tray = null;
|
||||||
app.on('ready', function() {
|
app.on('ready', () => {
|
||||||
tray = new Tray('/path/to/icon.png');
|
tray = new Tray('/path/to/icon.png');
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
@ -84,7 +84,7 @@ To solve this, you can turn off node integration in Electron:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// In the main process.
|
// In the main process.
|
||||||
var mainWindow = new BrowserWindow({
|
let mainWindow = new BrowserWindow({
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
nodeIntegration: false
|
nodeIntegration: false
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,7 @@ a value it and its type is noted below. If you were to listen and respond to
|
||||||
this event it might look something like this:
|
this event it might look something like this:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
Alarm.on('wake-up', function(time) {
|
Alarm.on('wake-up', (time) => {
|
||||||
console.log(time)
|
console.log(time)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
|
@ -71,8 +71,8 @@ require('/path/to/example.asar/dir/module.js');
|
||||||
You can also display a web page in an `asar` archive with `BrowserWindow`:
|
You can also display a web page in an `asar` archive with `BrowserWindow`:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const BrowserWindow = require('electron').BrowserWindow;
|
const { BrowserWindow } = require('electron');
|
||||||
var win = new BrowserWindow({width: 800, height: 600});
|
let win = new BrowserWindow({width: 800, height: 600});
|
||||||
win.loadURL('file:///path/to/example.asar/static/index.html');
|
win.loadURL('file:///path/to/example.asar/static/index.html');
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ For example, to get a file with `$.get`:
|
||||||
```html
|
```html
|
||||||
<script>
|
<script>
|
||||||
var $ = require('./jquery.min.js');
|
var $ = require('./jquery.min.js');
|
||||||
$.get('file:///path/to/example.asar/file.txt', function(data) {
|
$.get('file:///path/to/example.asar/file.txt', (data) => {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -99,7 +99,7 @@ content of `asar` archive as file. For this purpose you can use the built-in
|
||||||
`original-fs` module which provides original `fs` APIs without `asar` support:
|
`original-fs` module which provides original `fs` APIs without `asar` support:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var originalFs = require('original-fs');
|
const originalFs = require('original-fs');
|
||||||
originalFs.readFileSync('/path/to/example.asar');
|
originalFs.readFileSync('/path/to/example.asar');
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ the currently running operating system's native notification APIs to display it.
|
||||||
**Note:** Since this is an HTML5 API it is only available in the renderer process.
|
**Note:** Since this is an HTML5 API it is only available in the renderer process.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var myNotification = new Notification('Title', {
|
let myNotification = new Notification('Title', {
|
||||||
body: 'Lorem Ipsum Dolor Sit Amet'
|
body: 'Lorem Ipsum Dolor Sit Amet'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -117,8 +117,8 @@ const electron = require('electron');
|
||||||
const app = electron.app;
|
const app = electron.app;
|
||||||
const Menu = electron.Menu;
|
const Menu = electron.Menu;
|
||||||
|
|
||||||
var dockMenu = Menu.buildFromTemplate([
|
const dockMenu = Menu.buildFromTemplate([
|
||||||
{ label: 'New Window', click: function() { console.log('New Window'); } },
|
{ label: 'New Window', click: () => { console.log('New Window'); } },
|
||||||
{ label: 'New Window with Settings', submenu: [
|
{ label: 'New Window with Settings', submenu: [
|
||||||
{ label: 'Basic' },
|
{ label: 'Basic' },
|
||||||
{ label: 'Pro'}
|
{ label: 'Pro'}
|
||||||
|
@ -209,24 +209,25 @@ You can use [BrowserWindow.setThumbarButtons][setthumbarbuttons] to set
|
||||||
thumbnail toolbar in your application:
|
thumbnail toolbar in your application:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const BrowserWindow = require('electron').BrowserWindow;
|
const { BrowserWindow } = require('electron');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
var win = new BrowserWindow({
|
let win = new BrowserWindow({
|
||||||
width: 800,
|
width: 800,
|
||||||
height: 600
|
height: 600
|
||||||
});
|
});
|
||||||
|
|
||||||
win.setThumbarButtons([
|
win.setThumbarButtons([
|
||||||
{
|
{
|
||||||
tooltip: "button1",
|
tooltip: "button1",
|
||||||
icon: path.join(__dirname, 'button1.png'),
|
icon: path.join(__dirname, 'button1.png'),
|
||||||
click: function() { console.log("button2 clicked"); }
|
click: () => { console.log("button2 clicked"); }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
tooltip: "button2",
|
tooltip: "button2",
|
||||||
icon: path.join(__dirname, 'button2.png'),
|
icon: path.join(__dirname, 'button2.png'),
|
||||||
flags:['enabled', 'dismissonclick'],
|
flags:['enabled', 'dismissonclick'],
|
||||||
click: function() { console.log("button2 clicked."); }
|
click: () => { console.log("button2 clicked."); }
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
```
|
```
|
||||||
|
@ -266,7 +267,7 @@ To set the progress bar for a Window, you can use the
|
||||||
[BrowserWindow.setProgressBar][setprogressbar] API:
|
[BrowserWindow.setProgressBar][setprogressbar] API:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var window = new BrowserWindow({...});
|
let window = new BrowserWindow({...});
|
||||||
window.setProgressBar(0.5);
|
window.setProgressBar(0.5);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -293,7 +294,7 @@ To set the overlay icon for a window, you can use the
|
||||||
[BrowserWindow.setOverlayIcon][setoverlayicon] API:
|
[BrowserWindow.setOverlayIcon][setoverlayicon] API:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var window = new BrowserWindow({...});
|
let window = new BrowserWindow({...});
|
||||||
window.setOverlayIcon('path/to/overlay.png', 'Description for overlay');
|
window.setOverlayIcon('path/to/overlay.png', 'Description for overlay');
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -315,7 +316,7 @@ To set the represented file of window, you can use the
|
||||||
[BrowserWindow.setDocumentEdited][setdocumentedited] APIs:
|
[BrowserWindow.setDocumentEdited][setdocumentedited] APIs:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var window = new BrowserWindow({...});
|
let window = new BrowserWindow({...});
|
||||||
window.setRepresentedFilename('/etc/passwd');
|
window.setRepresentedFilename('/etc/passwd');
|
||||||
window.setDocumentEdited(true);
|
window.setDocumentEdited(true);
|
||||||
```
|
```
|
||||||
|
|
|
@ -10,10 +10,11 @@ const electron = require('electron');
|
||||||
const app = electron.app;
|
const app = electron.app;
|
||||||
const BrowserWindow = electron.BrowserWindow;
|
const BrowserWindow = electron.BrowserWindow;
|
||||||
|
|
||||||
var onlineStatusWindow;
|
let onlineStatusWindow;
|
||||||
app.on('ready', function() {
|
|
||||||
|
app.on('ready', () => {
|
||||||
onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false });
|
onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false });
|
||||||
onlineStatusWindow.loadURL('file://' + __dirname + '/online-status.html');
|
onlineStatusWindow.loadURL(`file://${__dirname}/online-status.html`);
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -24,7 +25,7 @@ _online-status.html_
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<script>
|
<script>
|
||||||
var alertOnlineStatus = function() {
|
const alertOnlineStatus = () => {
|
||||||
window.alert(navigator.onLine ? 'online' : 'offline');
|
window.alert(navigator.onLine ? 'online' : 'offline');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -51,13 +52,14 @@ const app = electron.app;
|
||||||
const ipcMain = electron.ipcMain;
|
const ipcMain = electron.ipcMain;
|
||||||
const BrowserWindow = electron.BrowserWindow;
|
const BrowserWindow = electron.BrowserWindow;
|
||||||
|
|
||||||
var onlineStatusWindow;
|
let onlineStatusWindow;
|
||||||
app.on('ready', function() {
|
|
||||||
|
app.on('ready', () => {
|
||||||
onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false });
|
onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false });
|
||||||
onlineStatusWindow.loadURL('file://' + __dirname + '/online-status.html');
|
onlineStatusWindow.loadURL(`file://${__dirname}/online-status.html`);
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on('online-status-changed', function(event, status) {
|
ipcMain.on('online-status-changed', (event, status) => {
|
||||||
console.log(status);
|
console.log(status);
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
@ -69,8 +71,8 @@ _online-status.html_
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<script>
|
<script>
|
||||||
const ipcRenderer = require('electron').ipcRenderer;
|
const { ipcRenderer } = require('electron');
|
||||||
var updateOnlineStatus = function() {
|
const updateOnlineStatus = () => {
|
||||||
ipcRenderer.send('online-status-changed', navigator.onLine ? 'online' : 'offline');
|
ipcRenderer.send('online-status-changed', navigator.onLine ? 'online' : 'offline');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -82,54 +82,54 @@ example being:
|
||||||
```javascript
|
```javascript
|
||||||
const electron = require('electron')
|
const electron = require('electron')
|
||||||
// Module to control application life.
|
// Module to control application life.
|
||||||
const app = electron.app
|
const app = electron.app;
|
||||||
// Module to create native browser window.
|
// Module to create native browser window.
|
||||||
const BrowserWindow = electron.BrowserWindow
|
const BrowserWindow = electron.BrowserWindow;
|
||||||
|
|
||||||
// Keep a global reference of the window object, if you don't, the window will
|
// Keep a global reference of the window object, if you don't, the window will
|
||||||
// be closed automatically when the JavaScript object is garbage collected.
|
// be closed automatically when the JavaScript object is garbage collected.
|
||||||
let mainWindow
|
let mainWindow;
|
||||||
|
|
||||||
function createWindow () {
|
function createWindow () {
|
||||||
// Create the browser window.
|
// Create the browser window.
|
||||||
mainWindow = new BrowserWindow({width: 800, height: 600})
|
mainWindow = new BrowserWindow({width: 800, height: 600});
|
||||||
|
|
||||||
// and load the index.html of the app.
|
// and load the index.html of the app.
|
||||||
mainWindow.loadURL('file://' + __dirname + '/index.html')
|
mainWindow.loadURL(`file://${__dirname}/index.html`);
|
||||||
|
|
||||||
// Open the DevTools.
|
// Open the DevTools.
|
||||||
mainWindow.webContents.openDevTools()
|
mainWindow.webContents.openDevTools();
|
||||||
|
|
||||||
// Emitted when the window is closed.
|
// Emitted when the window is closed.
|
||||||
mainWindow.on('closed', function () {
|
mainWindow.on('closed', () => {
|
||||||
// Dereference the window object, usually you would store windows
|
// Dereference the window object, usually you would store windows
|
||||||
// in an array if your app supports multi windows, this is the time
|
// in an array if your app supports multi windows, this is the time
|
||||||
// when you should delete the corresponding element.
|
// when you should delete the corresponding element.
|
||||||
mainWindow = null
|
mainWindow = null;
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method will be called when Electron has finished
|
// This method will be called when Electron has finished
|
||||||
// initialization and is ready to create browser windows.
|
// initialization and is ready to create browser windows.
|
||||||
// Some APIs can only be used after this event occurs.
|
// Some APIs can only be used after this event occurs.
|
||||||
app.on('ready', createWindow)
|
app.on('ready', createWindow);
|
||||||
|
|
||||||
// Quit when all windows are closed.
|
// Quit when all windows are closed.
|
||||||
app.on('window-all-closed', function () {
|
app.on('window-all-closed', () => {
|
||||||
// On OS X it is common for applications and their menu bar
|
// On OS X it is common for applications and their menu bar
|
||||||
// to stay active until the user quits explicitly with Cmd + Q
|
// to stay active until the user quits explicitly with Cmd + Q
|
||||||
if (process.platform !== 'darwin') {
|
if (process.platform !== 'darwin') {
|
||||||
app.quit()
|
app.quit();
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
app.on('activate', function () {
|
app.on('activate', () => {
|
||||||
// On OS X it's common to re-create a window in the app when the
|
// On OS X it's common to re-create a window in the app when the
|
||||||
// dock icon is clicked and there are no other windows open.
|
// dock icon is clicked and there are no other windows open.
|
||||||
if (mainWindow === null) {
|
if (mainWindow === null) {
|
||||||
createWindow()
|
createWindow();
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
// In this file you can include the rest of your app's specific main process
|
// In this file you can include the rest of your app's specific main process
|
||||||
// code. You can also put them in separate files and require them here.
|
// code. You can also put them in separate files and require them here.
|
||||||
|
|
|
@ -28,7 +28,7 @@ app.commandLine.appendSwitch('ppapi-flash-path', '/path/to/libpepflashplayer.so'
|
||||||
// Optional: Specify flash version, for example, v17.0.0.169
|
// Optional: Specify flash version, for example, v17.0.0.169
|
||||||
app.commandLine.appendSwitch('ppapi-flash-version', '17.0.0.169');
|
app.commandLine.appendSwitch('ppapi-flash-version', '17.0.0.169');
|
||||||
|
|
||||||
app.on('ready', function() {
|
app.on('ready', () => {
|
||||||
mainWindow = new BrowserWindow({
|
mainWindow = new BrowserWindow({
|
||||||
width: 800,
|
width: 800,
|
||||||
height: 600,
|
height: 600,
|
||||||
|
@ -36,7 +36,7 @@ app.on('ready', function() {
|
||||||
plugins: true
|
plugins: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mainWindow.loadURL('file://' + __dirname + '/index.html');
|
mainWindow.loadURL(`file://${__dirname}/index.html`);
|
||||||
// Something else
|
// Something else
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
|
@ -43,7 +43,7 @@ and where to find Electron's binary:
|
||||||
```javascript
|
```javascript
|
||||||
const webdriver = require('selenium-webdriver');
|
const webdriver = require('selenium-webdriver');
|
||||||
|
|
||||||
var driver = new webdriver.Builder()
|
const driver = new webdriver.Builder()
|
||||||
// The "9515" is the port opened by chrome driver.
|
// The "9515" is the port opened by chrome driver.
|
||||||
.usingServer('http://localhost:9515')
|
.usingServer('http://localhost:9515')
|
||||||
.withCapabilities({
|
.withCapabilities({
|
||||||
|
@ -58,7 +58,7 @@ var driver = new webdriver.Builder()
|
||||||
driver.get('http://www.google.com');
|
driver.get('http://www.google.com');
|
||||||
driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');
|
driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');
|
||||||
driver.findElement(webdriver.By.name('btnG')).click();
|
driver.findElement(webdriver.By.name('btnG')).click();
|
||||||
driver.wait(function() {
|
driver.wait(() => {
|
||||||
return driver.getTitle().then(function(title) {
|
return driver.getTitle().then(function(title) {
|
||||||
return title === 'webdriver - Google Search';
|
return title === 'webdriver - Google Search';
|
||||||
});
|
});
|
||||||
|
@ -94,29 +94,29 @@ $ npm install webdriverio
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const webdriverio = require('webdriverio');
|
const webdriverio = require('webdriverio');
|
||||||
var options = {
|
const options = {
|
||||||
host: "localhost", // Use localhost as chrome driver server
|
host: 'localhost', // Use localhost as chrome driver server
|
||||||
port: 9515, // "9515" is the port opened by chrome driver.
|
port: 9515, // "9515" is the port opened by chrome driver.
|
||||||
desiredCapabilities: {
|
desiredCapabilities: {
|
||||||
browserName: 'chrome',
|
browserName: 'chrome',
|
||||||
chromeOptions: {
|
chromeOptions: {
|
||||||
binary: '/Path-to-Your-App/electron', // Path to your Electron binary.
|
binary: '/Path-to-Your-App/electron', // Path to your Electron binary.
|
||||||
args: [/* cli arguments */] // Optional, perhaps 'app=' + /path/to/your/app/
|
args: [/* cli arguments */] // Optional, perhaps 'app=' + /path/to/your/app/
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var client = webdriverio.remote(options);
|
var client = webdriverio.remote(options);
|
||||||
|
|
||||||
client
|
client
|
||||||
.init()
|
.init()
|
||||||
.url('http://google.com')
|
.url('http://google.com')
|
||||||
.setValue('#q', 'webdriverio')
|
.setValue('#q', 'webdriverio')
|
||||||
.click('#btnG')
|
.click('#btnG')
|
||||||
.getTitle().then(function(title) {
|
.getTitle().then((title) => {
|
||||||
console.log('Title was: ' + title);
|
console.log('Title was: ' + title);
|
||||||
})
|
})
|
||||||
.end();
|
.end();
|
||||||
```
|
```
|
||||||
|
|
||||||
## Workflow
|
## Workflow
|
||||||
|
|
|
@ -59,8 +59,8 @@ app.commandLine.appendSwitch('widevine-cdm-path', '/path/to/widevinecdmadapter.p
|
||||||
// The version of plugin can be got from `chrome://plugins` page in Chrome.
|
// The version of plugin can be got from `chrome://plugins` page in Chrome.
|
||||||
app.commandLine.appendSwitch('widevine-cdm-version', '1.4.8.866');
|
app.commandLine.appendSwitch('widevine-cdm-version', '1.4.8.866');
|
||||||
|
|
||||||
var mainWindow = null;
|
let mainWindow = null;
|
||||||
app.on('ready', function() {
|
app.on('ready', () => {
|
||||||
mainWindow = new BrowserWindow({
|
mainWindow = new BrowserWindow({
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
// The `plugins` have to be enabled.
|
// The `plugins` have to be enabled.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue