|
@@ -219,6 +219,21 @@ Emitted when devtools is closed.
|
|
|
|
|
|
Emitted when devtools is focused / opened.
|
|
|
|
|
|
+### Event: 'app-command':
|
|
|
+
|
|
|
+Emitted when an [App Command](https://msdn.microsoft.com/en-us/library/windows/desktop/ms646275(v=vs.85).aspx) is invoked. These are typically related to keyboard media keys or browser commands, as well as the "Back" button built into some mice on Windows.
|
|
|
+
|
|
|
+```js
|
|
|
+someWindow.on('app-command', function(e, cmd) {
|
|
|
+ // Navigate the window back when the user hits their mouse back button
|
|
|
+ if (cmd === 'browser-backward' && someWindow.webContents.canGoBack()) {
|
|
|
+ someWindow.webContents.goBack();
|
|
|
+ }
|
|
|
+});
|
|
|
+```
|
|
|
+
|
|
|
+__Note__: This event is only fired on Windows.
|
|
|
+
|
|
|
### Class Method: BrowserWindow.getAllWindows()
|
|
|
|
|
|
Returns an array of all opened browser windows.
|
|
@@ -517,6 +532,10 @@ Opens the developer tools.
|
|
|
|
|
|
Closes the developer tools.
|
|
|
|
|
|
+### BrowserWindow.isDevToolsOpened()
|
|
|
+
|
|
|
+Returns whether the developer tools are opened.
|
|
|
+
|
|
|
### BrowserWindow.toggleDevTools()
|
|
|
|
|
|
Toggle the developer tools.
|
|
@@ -753,10 +772,6 @@ Calling `event.preventDefault()` can prevent the navigation.
|
|
|
|
|
|
Emitted when the renderer process is crashed.
|
|
|
|
|
|
-### Event: 'gpu-crashed'
|
|
|
-
|
|
|
-Emitted when the gpu process is crashed.
|
|
|
-
|
|
|
### Event: 'plugin-crashed'
|
|
|
|
|
|
* `event` Event
|
|
@@ -976,10 +991,29 @@ size.
|
|
|
Prints windows' web page as PDF with Chromium's preview printing custom
|
|
|
settings.
|
|
|
|
|
|
-By default, the options will be
|
|
|
+By default, an empty `options` will be regarded as
|
|
|
`{marginsType:0, printBackgrounds:false, printSelectionOnly:false,
|
|
|
landscape:false}`.
|
|
|
|
|
|
+```javascript
|
|
|
+var BrowserWindow = require('browser-window');
|
|
|
+var fs = require('fs');
|
|
|
+
|
|
|
+var win = new BrowserWindow({width: 800, height: 600});
|
|
|
+win.loadUrl("http://github.com");
|
|
|
+
|
|
|
+win.webContents.on("did-finish-load", function() {
|
|
|
+ // Use default printing options
|
|
|
+ win.webContents.printToPDF({}, function(error, data) {
|
|
|
+ if (error) throw error;
|
|
|
+ fs.writeFile(dist, data, function(error) {
|
|
|
+ if (err)
|
|
|
+ alert('write pdf file error', error);
|
|
|
+ })
|
|
|
+ })
|
|
|
+});
|
|
|
+```
|
|
|
+
|
|
|
### WebContents.send(channel[, args...])
|
|
|
|
|
|
* `channel` String
|
|
@@ -1020,3 +1054,90 @@ app.on('ready', function() {
|
|
|
is different from the handlers on the main process.
|
|
|
2. There is no way to send synchronous messages from the main process to a
|
|
|
renderer process, because it would be very easy to cause dead locks.
|
|
|
+
|
|
|
+## Class: WebContents.session.cookies
|
|
|
+
|
|
|
+The `cookies` gives you ability to query and modify cookies, an example is:
|
|
|
+
|
|
|
+```javascipt
|
|
|
+var BrowserWindow = require('browser-window');
|
|
|
+
|
|
|
+var win = new BrowserWindow({ width: 800, height: 600 });
|
|
|
+
|
|
|
+win.loadUrl('https://github.com');
|
|
|
+
|
|
|
+win.webContents.on('did-finish-load', function() {
|
|
|
+ // Query all cookies.
|
|
|
+ win.webContents.session.cookies.get({}, function(error, cookies) {
|
|
|
+ if (error) throw error;
|
|
|
+ console.log(cookies);
|
|
|
+ });
|
|
|
+
|
|
|
+ // Query all cookies that are associated with a specific url.
|
|
|
+ win.webContents.session.cookies.get({ url : "http://www.github.com" },
|
|
|
+ function(error, cookies) {
|
|
|
+ if (error) throw error;
|
|
|
+ console.log(cookies);
|
|
|
+ });
|
|
|
+
|
|
|
+ // Set a cookie with the given cookie data;
|
|
|
+ // may overwrite equivalent cookies if they exist.
|
|
|
+ win.webContents.session.cookies.set(
|
|
|
+ { url : "http://www.github.com", name : "dummy_name", value : "dummy"},
|
|
|
+ function(error, cookies) {
|
|
|
+ if (error) throw error;
|
|
|
+ console.log(cookies);
|
|
|
+ });
|
|
|
+});
|
|
|
+```
|
|
|
+
|
|
|
+### WebContents.session.cookies.get(details, callback)
|
|
|
+
|
|
|
+* `details` Object
|
|
|
+ * `url` String - Retrieves cookies which are associated with `url`.
|
|
|
+ Empty imples retrieving cookies of all urls.
|
|
|
+ * `name` String - Filters cookies by name
|
|
|
+ * `domain` String - Retrieves cookies whose domains match or are subdomains of `domains`
|
|
|
+ * `path` String - Retrieves cookies whose path matches `path`
|
|
|
+ * `secure` Boolean - Filters cookies by their Secure property
|
|
|
+ * `session` Boolean - Filters out session or persistent cookies.
|
|
|
+* `callback` Function - function(error, cookies)
|
|
|
+ * `error` Error
|
|
|
+ * `cookies` Array - array of `cookie` objects.
|
|
|
+ * `cookie` - Object
|
|
|
+ * `name` String - The name of the cookie
|
|
|
+ * `value` String - The value of the cookie
|
|
|
+ * `domain` String - The domain of the cookie
|
|
|
+ * `host_only` String - Whether the cookie is a host-only cookie
|
|
|
+ * `path` String - The path of the cookie
|
|
|
+ * `secure` Boolean - Whether the cookie is marked as Secure (typically HTTPS)
|
|
|
+ * `http_only` Boolean - Whether the cookie is marked as HttpOnly
|
|
|
+ * `session` Boolean - Whether the cookie is a session cookie or a persistent
|
|
|
+ * cookie with an expiration date.
|
|
|
+ * `expirationDate` Double - (Option) The expiration date of the cookie as
|
|
|
+ the number of seconds since the UNIX epoch. Not provided for session cookies.
|
|
|
+
|
|
|
+
|
|
|
+### WebContents.session.cookies.set(details, callback)
|
|
|
+
|
|
|
+* `details` Object
|
|
|
+ * `url` String - Retrieves cookies which are associated with `url`
|
|
|
+ * `name` String - The name of the cookie. Empty by default if omitted.
|
|
|
+ * `value` String - The value of the cookie. Empty by default if omitted.
|
|
|
+ * `domain` String - The domain of the cookie. Empty by default if omitted.
|
|
|
+ * `path` String - The path of the cookie. Empty by default if omitted.
|
|
|
+ * `secure` Boolean - Whether the cookie should be marked as Secure. Defaults to false.
|
|
|
+ * `session` Boolean - Whether the cookie should be marked as HttpOnly. Defaults to false.
|
|
|
+ * `expirationDate` Double - The expiration date of the cookie as the number of
|
|
|
+ seconds since the UNIX epoch. If omitted, the cookie becomes a session cookie.
|
|
|
+
|
|
|
+* `callback` Function - function(error)
|
|
|
+ * `error` Error
|
|
|
+
|
|
|
+### WebContents.session.cookies.remove(details, callback)
|
|
|
+
|
|
|
+* `details` Object
|
|
|
+ * `url` String - The URL associated with the cookie
|
|
|
+ * `name` String - The name of cookie to remove
|
|
|
+* `callback` Function - function(error)
|
|
|
+ * `error` Error
|