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

feat(devtools): Add devtools existence check to pressing the extension button #19287

Open
wants to merge 32 commits into
base: main
Choose a base branch
from

Conversation

WayneFerrao
Copy link
Contributor

@WayneFerrao WayneFerrao commented Jan 18, 2024

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.

Screenshot 2024-02-14 at 2 23 41 PM

Screenshot 2024-02-14 at 2 24 14 PM

@WayneFerrao WayneFerrao requested review from a team as code owners January 18, 2024 22:18
@github-actions github-actions bot added base: main PRs targeted against main branch area: build Build related issues labels Jan 18, 2024
@github-actions github-actions bot removed the area: build Build related issues label Jan 18, 2024
@@ -239,6 +245,22 @@ export function DevtoolsView(props: DevtoolsViewProps): React.ReactElement {
};
}, [messageRelay, setSupportedFeatures, telemetryOptInLogger]);

React.useEffect(() => {
const handleRequest = (event) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

  • Is event used in any part of the hook?
  • Should add return type for handleRequest.
  • I believe we should include supportedFeatures inside the dependency array, since we want to trigger useEffect whenever there's a change in underlying supportedFeatures value?

Copy link
Contributor Author

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

@@ -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" });
Copy link
Contributor

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)?

Copy link
Contributor

@alexvy86 alexvy86 Jan 31, 2024

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.

@msfluid-bot
Copy link
Collaborator

msfluid-bot commented Feb 2, 2024

Could not find a usable baseline build with search starting at CI 40e6559

Generated by 🚫 dangerJS against cbd0ede

@WayneFerrao WayneFerrao requested a review from a team February 5, 2024 21:06
Copy link
Contributor

@alexvy86 alexvy86 left a 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.

@WayneFerrao WayneFerrao requested a review from a team as a code owner February 6, 2024 20:04
*/
export async function initializePopupView(target: HTMLElement, tabId: number): Promise<void> {
const backgroundServiceConnection = await BackgroundConnection.Initialize({
// TODO: devtools-panel-specific source
Copy link
Contributor

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.

Copy link
Contributor

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).

)}
{foundDevtools === false && (
<div>
Devtools not found. Visit the documentation{" "}
Copy link
Contributor

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.

@@ -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.
Copy link
Contributor

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 :)

Copy link
Contributor

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.

Copy link
Contributor

@Josmithr Josmithr left a 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.

@Josmithr
Copy link
Contributor

Would you mind adding some screenshots to the PR description?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
base: main PRs targeted against main branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants