-
Notifications
You must be signed in to change notification settings - Fork 0
Clipboard
Perform copy and paste operations on the system clipboard.
The Electron.Clipboard API provides comprehensive access to the system clipboard, supporting multiple data formats including text, HTML, RTF, images, and custom data. It enables reading from and writing to the clipboard with platform-specific behavior.
Get an array of supported formats for the clipboard type.
Parameters:
-
type- Clipboard type
Returns:
An array of supported formats for the clipboard type.
Clears the clipboard content.
Parameters:
-
type- Clipboard type
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.
Returns:
Object containing title and url keys representing the bookmark in the clipboard.
macOS: The text on the find pasteboard. 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.
Returns:
The text on the find pasteboard.
Read the content in the clipboard as HTML markup.
Parameters:
-
type- Clipboard type
Returns:
The content in the clipboard as markup.
Read an image from the clipboard.
Parameters:
-
type- Clipboard type
Returns:
An image from the clipboard.
Read the content in the clipboard as RTF.
Parameters:
-
type- Clipboard type
Returns:
The content in the clipboard as RTF.
Read the content in the clipboard as plain text.
Parameters:
-
type- Clipboard type
Returns:
The content in the clipboard as plain text.
Writes data to the clipboard.
Parameters:
-
data- Data object to write -
type- Clipboard type
Writes the title 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.
Parameters:
-
title- Bookmark title -
url- Bookmark URL -
type- Clipboard type
macOS: Writes the text into the find pasteboard as plain text. This method uses synchronous IPC when called from the renderer process.
Parameters:
-
text- Text to write to find pasteboard
Writes markup to the clipboard.
Parameters:
-
markup- HTML markup to write -
type- Clipboard type
Writes an image to the clipboard.
Parameters:
-
image- Image to write to clipboard -
type- Clipboard type
Writes the text into the clipboard in RTF.
Parameters:
-
text- RTF content to write -
type- Clipboard type
Writes the text into the clipboard as plain text.
Parameters:
-
text- Text content to write -
type- Clipboard type
// Read text from clipboard
var text = await Electron.Clipboard.ReadTextAsync();
Console.WriteLine($"Clipboard text: {text}");
// Write text to clipboard
Electron.Clipboard.WriteText("Hello, Electron.NET!");
// Read with specific type
var html = await Electron.Clipboard.ReadHTMLAsync("public.main");// Copy formatted text
var htmlContent = "<h1>Title</h1><p>Some <strong>bold</strong> text</p>";
Electron.Clipboard.WriteHTML(htmlContent);
// Read RTF content
var rtf = await Electron.Clipboard.ReadRTFAsync();
Console.WriteLine($"RTF content: {rtf}");// Read image from clipboard
var image = await Electron.Clipboard.ReadImageAsync();
if (image != null)
{
Console.WriteLine($"Image size: {image.Size.Width}x{image.Size.Height}");
}
// Write image to clipboard
var nativeImage = NativeImage.CreateFromPath("screenshot.png");
Electron.Clipboard.WriteImage(nativeImage);// Read bookmark from clipboard
var bookmark = await Electron.Clipboard.ReadBookmarkAsync();
if (!string.IsNullOrEmpty(bookmark.Title))
{
Console.WriteLine($"Bookmark: {bookmark.Title} -> {bookmark.Url}");
}
// Write bookmark to clipboard
Electron.Clipboard.WriteBookmark("Electron.NET", "https://github.com/ElectronNET/Electron.NET");// Check available formats
var formats = await Electron.Clipboard.AvailableFormatsAsync();
Console.WriteLine($"Available formats: {string.Join(", ", formats)}");
// Clear clipboard
Electron.Clipboard.Clear();
// Write custom data
var data = new Data
{
Text = "Custom data",
Html = "<p>Custom HTML</p>",
Image = nativeImage
};
Electron.Clipboard.Write(data);// macOS specific find pasteboard operations
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
// Read find text
var findText = await Electron.Clipboard.ReadFindTextAsync();
Console.WriteLine($"Find text: {findText}");
// Write find text
Electron.Clipboard.WriteFindText("search term");
}- Electron.Shell - Work with file paths from clipboard
- Electron.Notification - Show clipboard operation results
- Electron Clipboard Documentation - Official Electron clipboard API
Want to contribute to this documentation? Please fork and create a PR! The Wiki is autogenerated from the /docs content in the repository.