Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore[DevTools]: make clipboardWrite optional for chromium #32262

Conversation

hoxyq
Copy link
Contributor

@hoxyq hoxyq commented Jan 29, 2025

Addresses #32244.

Chromium

We will use chrome.permissions for checking / requesting clipboardWrite permission before copying something to the clipboard.

Firefox

We will keep clipboardWrite as a required permission, because there is no reliable and working API for requesting optional permissions for extensions that are extending browser DevTools:

  • chrome.permissions is unavailable for devtools pages - https://bugzilla.mozilla.org/show_bug.cgi?id=1796933
  • You can't call chrome.permissions.request from background, because this instruction has to be executed inside user-event callback, basically only initiated by user.

I don't really want to come up with solutions like opening a new tab with a button that user has to click.

@hoxyq hoxyq requested a review from eps1lon January 29, 2025 13:49
@github-actions github-actions bot added the React Core Team Opened by a member of the React Core Team label Jan 29, 2025
@react-sizebot
Copy link

react-sizebot commented Jan 29, 2025

Comparing: 55b54b0...dfd27fb

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 6.68 kB 6.68 kB +0.05% 1.83 kB 1.83 kB
oss-stable/react-dom/cjs/react-dom-client.production.js +0.09% 514.64 kB 515.10 kB +0.05% 91.76 kB 91.81 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.69 kB 6.69 kB = 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js +0.20% 557.67 kB 558.79 kB +0.11% 99.01 kB 99.12 kB
facebook-www/ReactDOM-prod.classic.js +0.08% 596.61 kB 597.07 kB +0.05% 104.90 kB 104.95 kB
facebook-www/ReactDOM-prod.modern.js +0.08% 587.04 kB 587.50 kB +0.05% 103.36 kB 103.41 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-experimental/react-art/cjs/react-art.production.js +0.38% 321.32 kB 322.53 kB +0.18% 54.77 kB 54.87 kB
oss-experimental/react-reconciler/cjs/react-reconciler.production.js +0.29% 427.45 kB 428.68 kB +0.11% 68.84 kB 68.91 kB
oss-experimental/react-reconciler/cjs/react-reconciler.profiling.js +0.27% 480.35 kB 481.65 kB +0.14% 76.62 kB 76.73 kB
oss-experimental/react-art/cjs/react-art.development.js +0.27% 613.10 kB 614.76 kB +0.14% 97.76 kB 97.89 kB
oss-experimental/react-reconciler/cjs/react-reconciler.development.js +0.23% 715.01 kB 716.63 kB +0.13% 112.82 kB 112.97 kB
oss-experimental/react-dom/cjs/react-dom-profiling.profiling.js +0.21% 613.19 kB 614.48 kB +0.12% 107.72 kB 107.85 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js +0.20% 557.67 kB 558.79 kB +0.11% 99.01 kB 99.12 kB
react-native/shims/ReactNativeTypes.js = 8.37 kB 8.32 kB = 2.19 kB 2.19 kB

Generated by 🚫 dangerJS against c16b8ba

@hoxyq hoxyq force-pushed the react-devtools/make-clipboard-write-optional-for-chromium branch from 53719e0 to cdf5c81 Compare January 29, 2025 13:54
@hoxyq hoxyq force-pushed the react-devtools/make-clipboard-write-optional-for-chromium branch from cdf5c81 to 85d3d00 Compare January 29, 2025 13:58
return callback;
} else {
return async () => {
const alreadyContains = await chrome.permissions.contains(options);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need this check? I'd expect that chrome.permissions.request does not prompt if you already granted permissions. At least that's how I interpret "displaying a prompt to the user if necessary." (https://developer.chrome.com/docs/extensions/reference/api/permissions#method-request)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I believe when I was just requesting the permission, it was showing me the dialog window each time. I will double-check later today and follow-up on this with you.

Copy link
Contributor Author

@hoxyq hoxyq Jan 30, 2025

Choose a reason for hiding this comment

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

Checked that again, the request dialog is not shown for permissions that already granted, thanks for pointing out! Removed redundant check.

Comment on lines +153 to +155
onClick: withPermissionsCheck({permissions: ['clipboardWrite']}, () =>
copy(flamechartStackFrame.scriptUrl),
),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we currently have any copy that doesn't check permissions? Feels like every copy call should check those i.e. we should have the permission check built-into a custom copy function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I've double-checked every import of clipboard-js that we are using for copying to clipboard.

Ideally, we should stop using this deprecated npm package, and migrate to navigator.clipboard.writeText(...), but it will be a really tricky case for our current setup.

In short, React DevTools is portaling React roots to other containers, which are mounted in different document, because of the way browser sets up third-party panels for DevTools. This setup leaves the document, which handles user interactions (like click-to-copy), unfocused, and we can't perform navigator.clipboard.writeText(...) on unfocused documents.

@hoxyq hoxyq force-pushed the react-devtools/make-clipboard-write-optional-for-chromium branch from 85d3d00 to c16b8ba Compare January 30, 2025 20:03
@hoxyq hoxyq merged commit 221f300 into facebook:main Jan 30, 2025
191 checks passed
@hoxyq hoxyq deleted the react-devtools/make-clipboard-write-optional-for-chromium branch January 30, 2025 20:08
github-actions bot pushed a commit to Umasankar15/react that referenced this pull request Jan 31, 2025
…32262)

Addresses facebook#32244.

### Chromium
We will use
[chrome.permissions](https://developer.chrome.com/docs/extensions/reference/api/permissions)
for checking / requesting `clipboardWrite` permission before copying
something to the clipboard.

### Firefox
We will keep `clipboardWrite` as a required permission, because there is
no reliable and working API for requesting optional permissions for
extensions that are extending browser DevTools:
- `chrome.permissions` is unavailable for devtools pages -
https://bugzilla.mozilla.org/show_bug.cgi?id=1796933
- You can't call `chrome.permissions.request` from background, because
this instruction has to be executed inside user-event callback,
basically only initiated by user.

I don't really want to come up with solutions like opening a new tab
with a button that user has to click.

DiffTrain build for [221f300](facebook@221f300)
github-actions bot pushed a commit to Umasankar15/react that referenced this pull request Jan 31, 2025
…32262)

Addresses facebook#32244.

### Chromium
We will use
[chrome.permissions](https://developer.chrome.com/docs/extensions/reference/api/permissions)
for checking / requesting `clipboardWrite` permission before copying
something to the clipboard.

### Firefox
We will keep `clipboardWrite` as a required permission, because there is
no reliable and working API for requesting optional permissions for
extensions that are extending browser DevTools:
- `chrome.permissions` is unavailable for devtools pages -
https://bugzilla.mozilla.org/show_bug.cgi?id=1796933
- You can't call `chrome.permissions.request` from background, because
this instruction has to be executed inside user-event callback,
basically only initiated by user.

I don't really want to come up with solutions like opening a new tab
with a button that user has to click.

DiffTrain build for [221f300](facebook@221f300)
hoxyq added a commit that referenced this pull request Feb 3, 2025
We started using these globals in `react-devtools-shared/src/frontend`
code, forward-fixing #32262.
hoxyq added a commit that referenced this pull request Feb 7, 2025
Full list of changes:
* DevTools: refactor NativeStyleEditor, don't use custom cache
implementation ([hoxyq](https://github.com/hoxyq) in
[#32298](#32298))
* fix[react-devtools-fusebox]: add extension globals to build
([hoxyq](https://github.com/hoxyq) in
[#32297](#32297))
* DevTools: fix host component filter option title
([hoxyq](https://github.com/hoxyq) in
[#32296](#32296))
* chore[DevTools]: make clipboardWrite optional for chromium
([hoxyq](https://github.com/hoxyq) in
[#32262](#32262))
* DevTools: support useEffectEvent and forward-fix experimental prefix
support ([hoxyq](https://github.com/hoxyq) in
[#32106](#32106))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants