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
feat(devtools): Add devtools existence check to pressing the extension button #19287
base: main
Are you sure you want to change the base?
Conversation
f0acd3a
to
39a5125
Compare
39a5125
to
8f688a6
Compare
| @@ -239,6 +245,22 @@ export function DevtoolsView(props: DevtoolsViewProps): React.ReactElement { | |||
| }; | |||
| }, [messageRelay, setSupportedFeatures, telemetryOptInLogger]); | |||
|
|
|||
| React.useEffect(() => { | |||
| const handleRequest = (event) => { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Is
eventused in any part of the hook? - Should add return type for
handleRequest. - I believe we should include
supportedFeaturesinside the dependency array, since we want to triggeruseEffectwhenever there's a change in underlyingsupportedFeaturesvalue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, it isn't. The handler just send the response event. Will fix
packages/tools/devtools/devtools-browser-extension/src/popup/InitializePopupView.ts
Outdated
Show resolved
Hide resolved
| @@ -19,7 +18,9 @@ import { browser } from "../Globals"; | |||
| // If not, we may want to display an error message with a link to docs explaining how to | |||
| // use them. | |||
|
|
|||
| browser.tabs.query({ active: true, currentWindow: true }, (tab) => { | |||
| const port = browser.runtime.connect({ name: "popup-background-channel" }); | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to make sure I'm understanding correctly: this establishes a connection with the background script specifically? And the name we're providing is supposed to identify this (the caller)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name identifies the channel, more than the caller, IIRC. That's why I updated them at some point to be <oneside>-<otherside>-channel.
That said... I wonder if we need to use ports for this use case. browser.runtime.sendMessage() and browser.runtime.onMessage seem like they would do the trick, and I think they might be fine for communication between popup and background, which is more one-off than that between content and background. I think the message sent from popup to background would only trigger listeners set up with browser.runtime.onMessage() in the background script, but if background script did browser.runtime.sendMessage() that would get to all pages of the extension (popup, options, content) so maybe we'd need to make sure that content ignores this one.
Or actually, if popup used sendMessage(), background could use sendResponse() on the message it gets to respond synchronously (an async option is available too, all documented in onMessage()) directly to popup, and I guess we don't need to have special considerations in content in that case.
packages/tools/devtools/devtools-browser-extension/src/popup/PopupScript.ts
Outdated
Show resolved
Hide resolved
packages/tools/devtools/devtools-browser-extension/src/popup/PopupScript.ts
Outdated
Show resolved
Hide resolved
5544ce0
to
2f415f2
Compare
bf6abf1
to
8cad022
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's almost there! A few comments below.
packages/tools/devtools/devtools-browser-extension/src/popup/InitializePopupView.ts
Outdated
Show resolved
Hide resolved
packages/tools/devtools/devtools-browser-extension/src/popup/InitializePopupView.ts
Outdated
Show resolved
Hide resolved
packages/tools/devtools/devtools-browser-extension/src/popup/PopupView.tsx
Outdated
Show resolved
Hide resolved
packages/tools/devtools/devtools-browser-extension/src/popup/PopupView.tsx
Outdated
Show resolved
Hide resolved
packages/tools/devtools/devtools-browser-extension/src/popup/PopupView.tsx
Outdated
Show resolved
Hide resolved
packages/tools/devtools/devtools-browser-extension/src/popup/PopupView.tsx
Outdated
Show resolved
Hide resolved
packages/tools/devtools/devtools-browser-extension/src/popup/PopupView.tsx
Show resolved
Hide resolved
packages/tools/devtools/devtools-browser-extension/src/popup/PopupView.tsx
Outdated
Show resolved
Hide resolved
packages/tools/devtools/devtools-browser-extension/src/popup/PopupView.tsx
Outdated
Show resolved
Hide resolved
1e78359
to
bd8c85c
Compare
packages/tools/devtools/devtools-browser-extension/src/popup/PopupView.tsx
Outdated
Show resolved
Hide resolved
packages/tools/devtools/devtools-browser-extension/src/popup/PopupView.tsx
Outdated
Show resolved
Hide resolved
| */ | ||
| export async function initializePopupView(target: HTMLElement, tabId: number): Promise<void> { | ||
| const backgroundServiceConnection = await BackgroundConnection.Initialize({ | ||
| // TODO: devtools-panel-specific source |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend we make this change before merging - it will help us determine whether requests are coming from the popup or the devtools view when debugging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We just need to be careful to ensure existing flows continue to work (manual testing + auditing code to check for any places checking for the specific existing source here).
packages/tools/devtools/devtools-browser-extension/src/popup/PopupScript.ts
Outdated
Show resolved
Hide resolved
packages/tools/devtools/devtools-browser-extension/src/popup/PopupView.tsx
Outdated
Show resolved
Hide resolved
| )} | ||
| {foundDevtools === false && ( | ||
| <div> | ||
| Devtools not found. Visit the documentation{" "} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would vote for going into more detail here. E.g. "Fluid Devtools were not found running in the current tab. For details on how to enable the Devtools in your Fluid application, please refer to our documentation..."
@kashms interested in your thoughts on exact messaging for these. / If we should include any graphics or anything.
packages/tools/devtools/devtools-browser-extension/src/popup/PopupView.tsx
Outdated
Show resolved
Hide resolved
packages/tools/devtools/devtools-browser-extension/src/popup/PopupScript.ts
Outdated
Show resolved
Hide resolved
| @@ -19,7 +23,26 @@ import { browser } from "../Globals"; | |||
| // If not, we may want to display an error message with a link to docs explaining how to | |||
| // use them. | |||
|
|
|||
| browser.tabs.query({ active: true, currentWindow: true }, (tab) => { | |||
| // TODO: double check that tab selection can't change while popup is being displayed. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should verify this before merging. If it is possible for the tab selection to change while the popup is up, we should file a follow-up work item to handle tab selection changes gracefully, and update the TODO comment. If it isn't possible, we can just remove this comment :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@WayneFerrao I take it that it's not possible for the tab selection to change while the popup is being displayed? If so, let's leave a note to that effect as a comment, in case a future reader is wondering about this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking great! Left a few more comments, but from an infrastructure standpoint this looks perfect to me.
|
Would you mind adding some screenshots to the PR description? |
AB#4525
Description
This PR implements message passing to allow the devtools browser extension to check if the current webpage has devtools and what features it supports.