49e62f1261
* chore: bump chromium in DEPS to 95.0.4620.0 * chore: update patches * 3076261: Move args_ to private in ExtensionFunction https://chromium-review.googlesource.com/c/chromium/src/+/3076261 * [GURL -> SiteForCookies] content/public/browser/content_browser_client.h https://chromium-review.googlesource.com/c/chromium/src/+/3107759 * chore: fix -Wunreachable-code-return in node * Tracing to diagnose ContentScriptTracker-related bad message reports https://chromium-review.googlesource.com/c/chromium/src/+/3057922 * chore: bump chromium in DEPS to 95.0.4621.0 * chore: update patches * Remove title from the URL format on Windows. https://chromium-review.googlesource.com/c/chromium/src/+/3108445 * chore: bump chromium in DEPS to 95.0.4623.0 * Revert "chore: disable v8 oilpan" This reverts commit 5d255cf1d8e8efbb906047937a713279e5f800d0. (cherry picked from commit ba5cde4da2428020d99b7fb603c702878f95da78) * Change file paths in network context params to be relative. https://chromium-review.googlesource.com/c/chromium/src/+/3092927 * Code Health: Rename/replace content::WebUI::RegisterMessageCallback(). https://chromium-review.googlesource.com/c/chromium/src/+/3104691 * Migrate CanExecuteContentScriptSync to Mojo https://chromium-review.googlesource.com/c/chromium/src/+/3108452 * chore: update patches * remove unreachable code * Revert "Revert "chore: disable v8 oilpan"" This reverts commit fef495c0294e21760df51bddb5f7bf1ec9ed5f1e. * fixup mas patch * Reland "[include] Split out v8.h" https://chromium-review.googlesource.com/c/v8/v8/+/3113629 * chore: bump chromium in DEPS to 95.0.4624.0 * chore: bump chromium in DEPS to 95.0.4625.0 * chore: bump chromium in DEPS to 95.0.4626.0 * 3033504: Pass NavigationDownloadPolicy in CreateNewWindowParams https://chromium-review.googlesource.com/c/chromium/src/+/3033504 * 3058038: Introduce TestPrintingContext & test UpdatePrintSettings https://chromium-review.googlesource.com/c/chromium/src/+/3058038 * 3114943: [Conditional Focus][#4] Add tests and remove flag gating https://chromium-review.googlesource.com/c/chromium/src/+/3114943 * chore: update patch indices * chore: bump chromium in DEPS to 95.0.4627.0 * chore: update patches * 3093591: ozone: webpagepopups: calculate anchor for menu bounds. 4/* https://chromium-review.googlesource.com/c/chromium/src/+/3093591 * 3110414: [PA] Remove the leading cookie https://chromium-review.googlesource.com/c/chromium/src/+/3110414 * chore: update patches * 3076261: Move args_ to private in ExtensionFunction https://chromium-review.googlesource.com/c/chromium/src/+/3076261 * 3113629: Reland "[include] Split out v8.h" https://chromium-review.googlesource.com/c/v8/v8/+/3113629 * chore: bump chromium in DEPS to 95.0.4628.0 * chore: update patches * chore: bump chromium in DEPS to 95.0.4629.0 * chore: update patches * Fix chrome root store codegen for cross-compile builds. https://chromium-review.googlesource.com/c/chromium/src/+/3133701 Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
281 lines
7.9 KiB
Markdown
281 lines
7.9 KiB
Markdown
# clipboard
|
||
|
||
> Perform copy and paste operations on the system clipboard.
|
||
|
||
Process: [Main](../glossary.md#main-process), [Renderer](../glossary.md#renderer-process)
|
||
|
||
On Linux, there is also a `selection` clipboard. To manipulate it
|
||
you need to pass `selection` to each method:
|
||
|
||
```javascript
|
||
const { clipboard } = require('electron')
|
||
|
||
clipboard.writeText('Example String', 'selection')
|
||
console.log(clipboard.readText('selection'))
|
||
```
|
||
|
||
## Methods
|
||
|
||
The `clipboard` module has the following methods:
|
||
|
||
**Note:** Experimental APIs are marked as such and could be removed in future.
|
||
|
||
### `clipboard.readText([type])`
|
||
|
||
* `type` String (optional) - Can be `selection` or `clipboard`; default is 'clipboard'. `selection` is only available on Linux.
|
||
|
||
Returns `String` - The content in the clipboard as plain text.
|
||
|
||
```js
|
||
const { clipboard } = require('electron')
|
||
|
||
clipboard.writeText('hello i am a bit of text!')
|
||
|
||
const text = clipboard.readText()
|
||
console.log(text)
|
||
// hello i am a bit of text!'
|
||
```
|
||
|
||
### `clipboard.writeText(text[, type])`
|
||
|
||
* `text` String
|
||
* `type` String (optional) - Can be `selection` or `clipboard`; default is 'clipboard'. `selection` is only available on Linux.
|
||
|
||
Writes the `text` into the clipboard as plain text.
|
||
|
||
```js
|
||
const { clipboard } = require('electron')
|
||
|
||
const text = 'hello i am a bit of text!'
|
||
clipboard.writeText(text)
|
||
```
|
||
|
||
### `clipboard.readHTML([type])`
|
||
|
||
* `type` String (optional) - Can be `selection` or `clipboard`; default is 'clipboard'. `selection` is only available on Linux.
|
||
|
||
Returns `String` - The content in the clipboard as markup.
|
||
|
||
```js
|
||
const { clipboard } = require('electron')
|
||
|
||
clipboard.writeHTML('<b>Hi</b>')
|
||
const html = clipboard.readHTML()
|
||
|
||
console.log(html)
|
||
// <meta charset='utf-8'><b>Hi</b>
|
||
```
|
||
|
||
### `clipboard.writeHTML(markup[, type])`
|
||
|
||
* `markup` String
|
||
* `type` String (optional) - Can be `selection` or `clipboard`; default is 'clipboard'. `selection` is only available on Linux.
|
||
|
||
Writes `markup` to the clipboard.
|
||
|
||
```js
|
||
const { clipboard } = require('electron')
|
||
|
||
clipboard.writeHTML('<b>Hi</b')
|
||
```
|
||
|
||
### `clipboard.readImage([type])`
|
||
|
||
* `type` String (optional) - Can be `selection` or `clipboard`; default is 'clipboard'. `selection` is only available on Linux.
|
||
|
||
Returns [`NativeImage`](native-image.md) - The image content in the clipboard.
|
||
|
||
### `clipboard.writeImage(image[, type])`
|
||
|
||
* `image` [NativeImage](native-image.md)
|
||
* `type` String (optional) - Can be `selection` or `clipboard`; default is 'clipboard'. `selection` is only available on Linux.
|
||
|
||
Writes `image` to the clipboard.
|
||
|
||
### `clipboard.readRTF([type])`
|
||
|
||
* `type` String (optional) - Can be `selection` or `clipboard`; default is 'clipboard'. `selection` is only available on Linux.
|
||
|
||
Returns `String` - The content in the clipboard as RTF.
|
||
|
||
```js
|
||
const { clipboard } = require('electron')
|
||
|
||
clipboard.writeRTF('{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\nThis is some {\\b bold} text.\\par\n}')
|
||
|
||
const rtf = clipboard.readRTF()
|
||
console.log(rtf)
|
||
// {\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\nThis is some {\\b bold} text.\\par\n}
|
||
```
|
||
|
||
### `clipboard.writeRTF(text[, type])`
|
||
|
||
* `text` String
|
||
* `type` String (optional) - Can be `selection` or `clipboard`; default is 'clipboard'. `selection` is only available on Linux.
|
||
|
||
Writes the `text` into the clipboard in RTF.
|
||
|
||
```js
|
||
const { clipboard } = require('electron')
|
||
|
||
const rtf = '{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\nThis is some {\\b bold} text.\\par\n}'
|
||
clipboard.writeRTF(rtf)
|
||
```
|
||
|
||
### `clipboard.readBookmark()` _macOS_ _Windows_
|
||
|
||
Returns `Object`:
|
||
|
||
* `title` String
|
||
* `url` String
|
||
|
||
Returns an Object containing `title` and `url` keys representing the bookmark in
|
||
the clipboard. The `title` and `url` values will be empty strings when the
|
||
bookmark is unavailable. The `title` value will always be empty on Windows.
|
||
|
||
### `clipboard.writeBookmark(title, url[, type])` _macOS_ _Windows_
|
||
|
||
* `title` String - Unused on Windows
|
||
* `url` String
|
||
* `type` String (optional) - Can be `selection` or `clipboard`; default is 'clipboard'. `selection` is only available on Linux.
|
||
|
||
Writes the `title` (macOS only) and `url` into the clipboard as a bookmark.
|
||
|
||
**Note:** Most apps on Windows don't support pasting bookmarks into them so
|
||
you can use `clipboard.write` to write both a bookmark and fallback text to the
|
||
clipboard.
|
||
|
||
```js
|
||
const { clipboard } = require('electron')
|
||
|
||
clipboard.writeBookmark({
|
||
text: 'https://electronjs.org',
|
||
bookmark: 'Electron Homepage'
|
||
})
|
||
```
|
||
|
||
### `clipboard.readFindText()` _macOS_
|
||
|
||
Returns `String` - The text on the find pasteboard, which is the pasteboard that holds information about the current state of the active application’s find panel.
|
||
|
||
This method uses synchronous IPC when called from the renderer process.
|
||
The cached value is reread from the find pasteboard whenever the application is activated.
|
||
|
||
### `clipboard.writeFindText(text)` _macOS_
|
||
|
||
* `text` String
|
||
|
||
Writes the `text` into the find pasteboard (the pasteboard that holds information about the current state of the active application’s find panel) as plain text. This method uses synchronous IPC when called from the renderer process.
|
||
|
||
### `clipboard.clear([type])`
|
||
|
||
* `type` String (optional) - Can be `selection` or `clipboard`; default is 'clipboard'. `selection` is only available on Linux.
|
||
|
||
Clears the clipboard content.
|
||
|
||
### `clipboard.availableFormats([type])`
|
||
|
||
* `type` String (optional) - Can be `selection` or `clipboard`; default is 'clipboard'. `selection` is only available on Linux.
|
||
|
||
Returns `String[]` - An array of supported formats for the clipboard `type`.
|
||
|
||
```js
|
||
const { clipboard } = require('electron')
|
||
|
||
const formats = clipboard.availableFormats()
|
||
console.log(formats)
|
||
// [ 'text/plain', 'text/html' ]
|
||
```
|
||
|
||
### `clipboard.has(format[, type])` _Experimental_
|
||
|
||
* `format` String
|
||
* `type` String (optional) - Can be `selection` or `clipboard`; default is 'clipboard'. `selection` is only available on Linux.
|
||
|
||
Returns `Boolean` - Whether the clipboard supports the specified `format`.
|
||
|
||
```js
|
||
const { clipboard } = require('electron')
|
||
|
||
const hasFormat = clipboard.has('<p>selection</p>')
|
||
console.log(hasFormat)
|
||
// 'true' or 'false'
|
||
```
|
||
|
||
### `clipboard.read(format)` _Experimental_
|
||
|
||
* `format` String
|
||
|
||
Returns `String` - Reads `format` type from the clipboard.
|
||
|
||
`format` should contain valid ASCII characters and have `/` separator.
|
||
`a/c`, `a/bc` are valid formats while `/abc`, `abc/`, `a/`, `/a`, `a`
|
||
are not valid.
|
||
|
||
### `clipboard.readBuffer(format)` _Experimental_
|
||
|
||
* `format` String
|
||
|
||
Returns `Buffer` - Reads `format` type from the clipboard.
|
||
|
||
```js
|
||
const { clipboard } = require('electron')
|
||
|
||
const buffer = Buffer.from('this is binary', 'utf8')
|
||
clipboard.writeBuffer('public/utf8-plain-text', buffer)
|
||
|
||
const ret = clipboard.readBuffer('public/utf8-plain-text')
|
||
|
||
console.log(buffer.equals(out))
|
||
// true
|
||
```
|
||
|
||
### `clipboard.writeBuffer(format, buffer[, type])` _Experimental_
|
||
|
||
* `format` String
|
||
* `buffer` Buffer
|
||
* `type` String (optional) - Can be `selection` or `clipboard`; default is 'clipboard'. `selection` is only available on Linux.
|
||
|
||
Writes the `buffer` into the clipboard as `format`.
|
||
|
||
```js
|
||
const { clipboard } = require('electron')
|
||
|
||
const buffer = Buffer.from('writeBuffer', 'utf8')
|
||
clipboard.writeBuffer('public/utf8-plain-text', buffer)
|
||
```
|
||
|
||
### `clipboard.write(data[, type])`
|
||
|
||
* `data` Object
|
||
* `text` String (optional)
|
||
* `html` String (optional)
|
||
* `image` [NativeImage](native-image.md) (optional)
|
||
* `rtf` String (optional)
|
||
* `bookmark` String (optional) - The title of the URL at `text`.
|
||
* `type` String (optional) - Can be `selection` or `clipboard`; default is 'clipboard'. `selection` is only available on Linux.
|
||
|
||
Writes `data` to the clipboard.
|
||
|
||
```js
|
||
const { clipboard } = require('electron')
|
||
|
||
clipboard.write({
|
||
text: 'test',
|
||
html: '<b>Hi</b>',
|
||
rtf: '{\\rtf1\\utf8 text}',
|
||
bookmark: 'a title'
|
||
})
|
||
|
||
console.log(clipboard.readText())
|
||
// 'test'
|
||
|
||
console.log(clipboard.readHTML())
|
||
// <meta charset='utf-8'><b>Hi</b>
|
||
|
||
console.log(clipboard.readRTF())
|
||
// '{\\rtf1\\utf8 text}'
|
||
|
||
console.log(clipboard.readBookmark())
|
||
// { title: 'a title', url: 'test' }
|
||
```
|