-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Re-enable context menu options in Firefox #17681
Comments
@rpl and I looked into why, jump to element did not work. We found that When we paused on line 122 and manually overrode the node, inspect worked. One surprising thing we found was that |
We think the clipboard apis might not be working because they're called from the page. CC @rpl |
Luca was curious about $attribute in the inspect case. |
Ah, I tried to explain the way we were using
Does this help clear things up any? Or is some part of it unclear? |
This sounds...unexpected to me. Maybe it failed for a specific component, b'c that didn't have a DOM node, but in general it should work (and it should work the same for both browsers) |
@jasonLaster For the "jump to function definition" part, I just filed on bugzilla Bug 1605597 - DevTools API inspect binding called on a function should show it in the debugger panel and attached a patch to it. would you mind to edit the issue description and link the upstream bug there? |
I took a deeper look into the issue with the "copy to clipboard" action from the context menu (the one disabled in #17668 because it does trigger an error when used on Firefox) and it looks that my initial guess was right: as I mentioned in #17668 (comment) , on Firefox writing in the clipboard from outside of a "user handling" callback is possible but it requires the extension to ask for the This is the expected behavior on Firefox, and so we would need to fix it on the extension side. I've been able to workaround the issue and make it to work as expected by using the @jasonLaster @bvaughn Follows the diff of the small changes I applied locally to make it work as expected on Firefox: diff --git a/packages/react-devtools-extensions/firefox/manifest.json b/packages/react-devtools-extensions/firefox/manifest.json
index 498e04425..1918ab740 100644
--- a/packages/react-devtools-extensions/firefox/manifest.json
+++ b/packages/react-devtools-extensions/firefox/manifest.json
@@ -44,7 +44,7 @@
"scripts": ["build/background.js"]
},
- "permissions": ["file:///*", "http://*/*", "https://*/*"],
+ "permissions": ["file:///*", "http://*/*", "https://*/*", "clipboardWrite"],
"content_scripts": [
{
diff --git a/packages/react-devtools-extensions/src/injectGlobalHook.js b/packages/react-devtools-extensions/src/injectGlobalHook.js
index ea41a6c96..e60f875f3 100644
--- a/packages/react-devtools-extensions/src/injectGlobalHook.js
+++ b/packages/react-devtools-extensions/src/injectGlobalHook.js
@@ -91,3 +91,18 @@ if (sessionStorageGetItem(SESSION_STORAGE_RELOAD_AND_PROFILE_KEY) === 'true') {
injectCode(
';(' + installHook.toString() + '(window))' + saveNativeValues + detectReact,
);
+
+if (typeof exportFunction === 'function') {
+ // eslint-disable-next-line no-undef
+ exportFunction(
+ (text) => {
+ // Call clipboard.writeText from the extension content script
+ // (as it has the clipboardWrite permission) and return a Promise
+ // accessible to the webpage js code.
+ return new window.Promise((resolve, reject) =>
+ window.navigator.clipboard.writeText(text).then(resolve, reject));
+ },
+ window.wrappedJSObject.__REACT_DEVTOOLS_GLOBAL_HOOK__,
+ {defineAs: 'clipboardCopyText'}
+ );
+}
diff --git a/packages/react-devtools-shared/src/backend/utils.js b/packages/react-devtools-shared/src/backend/utils.js
index 47355f207..b0ce3e033 100644
--- a/packages/react-devtools-shared/src/backend/utils.js
+++ b/packages/react-devtools-shared/src/backend/utils.js
@@ -40,7 +40,19 @@ export function cleanForBridge(
export function copyToClipboard(value: any): void {
const safeToCopy = serializeToString(value);
- copy(safeToCopy === undefined ? 'undefined' : safeToCopy);
+ const text = safeToCopy === undefined ? 'undefined' : safeToCopy;
+ const {clipboardCopyText} = window.__REACT_DEVTOOLS_GLOBAL_HOOK__;
+
+ // On Firefox navigator.clipboard.writeText has to be called from
+ // the content script js code (because it requires the clipboardWrite
+ // permission to be allowed out of a "user handling" callback),
+ // clipboardCopyText is an helper injected into the page from.
+ // injectGlobalHook.
+ if (clipboardCopyText) {
+ clipboardCopyText(text).catch(err => {});
+ } else {
+ copy(text).catch(err => {});
+ }
}
export function copyWithSet( |
Fantastic! Thanks @rpl! |
FYI v4.4 (released today) re-enables the "copy" menu! |
@bvaughn @jasonLaster Bug 1605597 has been landed on Firefox 74 and so it should now be available in the Firefox nightly builds (and the "jump to definition" should work as expected once re-enabled). (@jasonLaster would you mind to update the TODO list in this issue's description comment accordingly? we can also remove or strikeout jump to |
Nice! Thanks for the update @rpl. |
Thanks @rpl! |
@rpl I tried re-enabling locally and testing against version 74.0a1 (2020-01-14) (64-bit) Overall it seems to be working now which is nice 👍 In many cases though, it points to the first line of a mangled file, so that's not ideal. There are still some cases in which I'm seeing the following error though:
For example:
I'll attach a build here if you'd like to reproduce it yourself! |
I took a quick look into this, starting from double-checking what is the behavior when It looks that the debugger server has been unable to identify where that function has been defined, I guess that something didn't worked as expected during the "source discovery phase". This issue doesn't look like a bug specific to the WebExtensions devtools API, but a more generic issue in the Firefox debugger internals, we should file a bug to look more deeply into it. @jasonLaster is the issue described above something that we may have already filed on bugzilla? would you mind to file it if we dont'? @bvaughn about the functions that are being pointed to the mangled file, do you remember how I could trigger one? |
You can just "store as global variable" (also using the context menu) and then interact with them. (Am I misunderstanding what you're asking?) |
@bvaughn hehe, sorry, I wasn't very clear :-) I was asking if there is a particular component that I could use to trigger the issue where "the debugger panel points it to a mangled file" |
@rpl Gotcha.
In Chrome, this jumps you to the specific line (with pretty formatted source): In Firefox nightly, this jumps you to a single line of (non pretty formatted) source: |
@bvaughn 👍 Thanks! The STR was really helpful to track it down quickly! @jasonLaster @bvaughn it looks that I may have tracked down both these new "
I've also attached 2 patches on them, which are the changes I've applied locally to fix these two issues (they are not yet on review, mostly because I'm going to push them to the CI to double-check if I may have broken some assumptions and related existing tests and there are a couple of additional test case to add). @jasonLaster would you mind to link them in this issue description in the meantime? |
Excellent. Thanks for the update @rpl! I've updated the description for you to link to the new issues. |
@bvaughn both Bug 1609671 and Bug 1609677 have been landed on Firefox 74 and should be available in the Nightly builds. |
Thanks for the update, @rpl! I think it should be safe to close this issue then 😄 Pleasure working with both of you. |
#17668 disabled support for "copy to clipboard" and "go to definition" context menu items in Firefox.
Use cases
The text was updated successfully, but these errors were encountered: