Skip to content

feat: clipboard module aligned with the W3C Clipboard API - #51707

Merged
jkleinsc merged 28 commits into
mainfrom
clipboard-refactor
Jul 29, 2026
Merged

jkleinsc merged 28 commits into
mainfrom
clipboard-refactor

Conversation

@jkleinsc

@jkleinsc jkleinsc commented May 19, 2026 •

Copy link
Copy Markdown
Member

Description of Change

This PR implements https://github.com/electron/rfcs/blob/main/text/0019-clipboard-rearchitecture.md

The clipboard module has been rearchitected to align with the W3C Clipboard API.
The four read/write methods now all return Promises, matching navigator.clipboard:

  • clipboard.read() returns Promise<ClipboardItem[]> matching the W3C ClipboardItem instance shape.
  • clipboard.write(items) returns Promise<void> and accepts an array of ClipboardItem instances constructed via new ClipboardItem({ [mime]: payload }) — modeled after the W3C ClipboardItem(items) constructor. Each payload value is Buffer | string | Object.
  • clipboard.readText() returns Promise<string>.
  • clipboard.writeText(text) returns Promise<void>.

Additionally, the clipboard module is no longer available in the renderer process.

For review purposes, I've broken up the PR into two changes:

  • ad7ca07 - remove clipboard API from renderer
  • b9e120c - clipboard refactor

This PR does not include adding the clipboardchange event or the privacyType option as those changes will be handled in separate PRs.

Assisted-By: Claude Opus 4.7

Checklist

Release Notes

Notes: clipboard module is now aligned with the W3C Clipboard API

@jkleinsc
jkleinsc requested review from a team as code owners May 19, 2026 20:59
@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label May 19, 2026
@jkleinsc jkleinsc added the target/43-x-y PR should also be added to the "43-x-y" branch. label May 19, 2026
@nikwen nikwen added the semver/major incompatible API changes label May 19, 2026
@ckerr

ckerr commented May 20, 2026 •

Copy link
Copy Markdown
Member

https://github.com/electron/electron/actions/runs/26124962619/job/76836513800

Been seeing a lot of build flakes like this the last couple days, but I'm not sure where they're coming from

2026-05-19T21:24:39.3712570Z ../../third_party/llvm-build/Release+Asserts/bin/clang++ -MMD -MF obj/third_party/perfetto/protos/perfetto/config/cpp/test_config.gen.o.d -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D_FORTIFY_SOURCE=3 -D__ARM_NEON__=1 -DCR_XCODE_BUILD=16F6 -DCR_CLANG_REVISION=\"llvmorg-23-init-10931-g20b6ec66-8\" -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE -D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS -D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS -D_LIBCPP_INSTRUMENTED_WITH_ASAN=0 -DCR_LIBCXX_REVISION=be1c391acca009d8d80535ce924e3d285451cdfa -DDCHECK_ALWAYS_ON=1 -DNDEBUG -DNVALGRIND -DDYNAMIC_ANNOTATIONS_ENABLED=0 -DPERFETTO_IMPLEMENTATION -I../.. -Igen -I../../buildtools/third_party/libc++ -Igen/third_party/perfetto -I../../third_party/protobuf/src -I../../third_party/perfetto -I../../third_party/perfetto/src/profiling/memory/include -I../../third_party/perfetto/include -Igen/third_party/perfetto/build_config -Wall -Wextra -Wimplicit-fallthrough -Wextra-semi -Wunreachable-code-aggressive -Wgnu -Wno-gnu-anonymous-struct -Wno-gnu-conditional-omitted-operand -Wno-gnu-include-next -Wno-gnu-label-as-value -Wno-gnu-redeclared-enum -Wno-gnu-statement-expression -Wno-gnu-zero-variadic-macro-arguments -Wno-zero-length-array -Wthread-safety -Wunguarded-availability -Wno-missing-field-initializers -Wno-unused-parameter -Wno-psabi -Wloop-analysis -Wno-unneeded-internal-declaration -Wno-cast-function-type -Wno-thread-safety-reference-return -Wno-nontrivial-memcall -Wno-uninitialized-const-pointer -Wno-unused-but-set-global -Wexit-time-destructors -Wshadow -Werror -fno-delete-null-pointer-checks -fno-strict-overflow -fno-ident -fno-math-errno -fno-strict-aliasing -fstack-protector -fcolor-diagnostics -fdiagnostics-show-inlining-chain -fmerge-all-constants -fcrash-diagnostics-dir=../clang-crashreports -fno-lifetime-dse -mllvm -instcombine-lower-dbg-declare=0 -mllvm -split-threshold-for-reg-with-hint=0 -ffp-contract=off -fcomplete-member-pointers --target=arm64-apple-macos -mno-outline -Wno-builtin-macro-redefined -D__DATE__= -D__TIME__= -D__TIMESTAMP__= -ffile-compilation-dir=. -no-canonical-prefixes --warning-suppression-mappings=../../build/config/warning_suppression.txt -ftrivial-auto-var-init=pattern -O2 -fno-omit-frame-pointer -gdwarf-4 -g1 -gdwarf-aranges -isysroot xcode_links/electron/MacOSX26.4.sdk -mmacos-version-min=12.0 -fsanitize=array-bounds -fsanitize-trap=array-bounds -fsanitize-ignore-for-ubsan-feature=array-bounds -Wno-unsafe-buffer-usage-in-static-sized-array -fsanitize=return -fsanitize-trap=return -fsanitize-ignore-for-ubsan-feature=return -fvisibility=hidden -Wheader-hygiene -Wstring-conversion -Wtautological-overlap-compare -Xclang -add-plugin -Xclang find-bad-constructs -Xclang -plugin-arg-find-bad-constructs -Xclang check-stack-allocated -Xclang -plugin-arg-find-bad-constructs -Xclang check-std-ranges-pipe-operator -Xclang -plugin-arg-find-bad-constructs -Xclang relax-ctor-checks-for-aggregates -Xclang -add-plugin -Xclang raw-ptr-plugin -Xclang -plugin-arg-raw-ptr-plugin -Xclang check-raw-ptr-to-stack-allocated -Xclang -plugin-arg-raw-ptr-plugin -Xclang disable-check-raw-ptr-to-stack-allocated-error -Xclang -plugin-arg-raw-ptr-plugin -Xclang raw-ptr-exclude-path=../../third_party/dawn/ -Xclang -plugin-arg-raw-ptr-plugin -Xclang raw-ptr-exclude-path=../../build/config/clang/chrome/test/fuzzing/webidl_fuzzing/ -Xclang -plugin-arg-raw-ptr-plugin -Xclang check-raw-ptr-fields -Xclang -plugin-arg-raw-ptr-plugin -Xclang check-span-fields -Xclang -plugin-arg-raw-ptr-plugin -Xclang check-raw-ref-fields -Xclang -plugin-arg-raw-ptr-plugin -Xclang no-special-treatment-for-oilpanized-paths -DUNSAFE_BUFFERS_BUILD -Wunsafe-buffer-usage -Wno-error=unsafe-buffer-usage -Xclang -add-plugin -Xclang unsafe-buffers -Xclang -plugin-arg-unsafe-buffers -Xclang ../../build/config/unsafe_buffers_paths.txt -Wno-invalid-offsetof -Wenum-compare-conditional -Wno-nullability-completeness -std=c++23 -Wno-trigraphs -fno-exceptions -fno-rtti -nostdinc++ -isystem../../third_party/libc++/src/include -isystem../../third_party/libc++abi/src/include -fvisibility-inlines-hidden  -c gen/third_party/perfetto/protos/perfetto/config/test_config.gen.cc -o obj/third_party/perfetto/protos/perfetto/config/cpp/test_config.gen.o
2026-05-19T21:24:39.3754120Z build step: cxx "./obj/third_party/perfetto/protos/perfetto/config/cpp/test_config.gen.o"
2026-05-19T21:24:39.3804280Z siso_rule: clang/cxx
2026-05-19T21:24:39.3915670Z stderr:
2026-05-19T21:24:39.4020720Z In file included from gen/third_party/perfetto/protos/perfetto/config/test_config.gen.cc:1:
2026-05-19T21:24:39.4124510Z In file included from ../../third_party/perfetto/include/perfetto/protozero/gen_field_helpers.h:20:
2026-05-19T21:24:39.4832610Z ../../third_party/perfetto/include/perfetto/protozero/message.h:20:10: fatal error: 'assert.h' file not found
2026-05-19T21:24:39.4833680Z    20 | #include <assert.h>
2026-05-19T21:24:39.5253480Z       |          ^~~~~~~~~~
2026-05-19T21:24:39.5263300Z 1 error generated.
2026-05-19T21:24:39.5271280Z 
2026-05-19T21:24:39.5271300Z 

@jkleinsc jkleinsc removed the target/43-x-y PR should also be added to the "43-x-y" branch. label May 20, 2026
Comment thread docs/breaking-changes.md Resolved
Comment thread docs/breaking-changes.md Resolved
Comment thread docs/breaking-changes.md Resolved
Comment thread docs/breaking-changes.md Resolved
Comment thread docs/breaking-changes.md Resolved
@dsanders11

Copy link
Copy Markdown
Member

@jkleinsc, can you merge main in here? Should clear the unrelated changes in typings/internal-ambient.d.ts and filenames.auto.gni (one unrelated line) now that we've cleaned those up.

@jkleinsc
jkleinsc force-pushed the clipboard-refactor branch 2 times, most recently from 80406fb to a5eeed5 Compare May 21, 2026 14:01

@erickzhao erickzhao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API LGTM

@samuelmaddock samuelmaddock left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API LGTM

Comment thread docs/api/structures/bookmark.md Resolved

@ckerr ckerr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review pt 1. C++ review is next

Comment thread docs/api/clipboard.md Resolved
Comment thread docs/api/clipboard.md Resolved
Comment thread docs/api/clipboard.md Resolved
Comment thread docs/api/clipboard.md Resolved
Comment thread docs/api/clipboard.md Resolved

@ckerr ckerr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C++ review pt 1

Comment thread docs/api/clipboard-item.md Resolved

@dsanders11 dsanders11 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a handful of comments, the main blocker being shell/common/api -> shell/browser/api rename.

Comment thread docs/api/clipboard-item.md Resolved
Comment thread docs/api/clipboard-item.md Resolved
Comment thread docs/api/structures/bookmark.md Resolved
Comment thread docs/api/clipboard.md Resolved
Comment thread spec/api-clipboard-spec.ts Resolved
Comment thread docs/api/clipboard-item.md Resolved
@jkleinsc
jkleinsc requested a review from MarshallOfSound July 23, 2026 16:24
Allows Returns `Promise<Blob>` in our docs instead of the workaround of Returns `Promise<import('buffer').Blob>`
@socket-security

socket-security Bot commented Jul 27, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updated@​electron/​typescript-definitions@​9.1.5 ⏵ 9.2.082 +110084 +188 +7100

View full report

@deepak1556 deepak1556 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jkleinsc
jkleinsc merged commit f6b2547 into main Jul 29, 2026
70 checks passed
@release-clerk

release-clerk Bot commented Jul 29, 2026

Copy link
Copy Markdown

Release Notes Persisted

clipboard module is now aligned with the W3C Clipboard API

@jkleinsc
jkleinsc deleted the clipboard-refactor branch July 29, 2026 00:41
@trop

trop Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "44-x-y", please check out #52508

@trop trop Bot added in-flight/44-x-y and removed target/44-x-y PR should also be added to the "44-x-y" branch. labels Jul 29, 2026
jkleinsc added a commit that referenced this pull request Jul 30, 2026
feat: clipboard module aligned with the W3C Clipboard API (#51707)

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: John Kleinschmidt <[email protected]>
@trop trop Bot added merged/44-x-y PR was merged to the "44-x-y" branch. and removed in-flight/44-x-y labels Jul 30, 2026
samhh added a commit to gitbutlerapp/gitbutler that referenced this pull request Aug 27, 2026
Includes the Window State API!:
  electron/electron#52270

Regarding the clipboard change see:
  electron/electron#51707
samhh added a commit to gitbutlerapp/gitbutler that referenced this pull request Aug 27, 2026
Includes the Window State API!:
  electron/electron#52270

Regarding the clipboard change see:
  electron/electron#51707
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

45-x-y api-review/approved ✅ merged/44-x-y PR was merged to the "44-x-y" branch. semver/major incompatible API changes

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

10 participants