-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
[blazor][wasm][debug]Press alt-shift-d and open firefox debug tab attached to the blazor app #46132
Conversation
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.
Thanks @thaystg.
I see that this was not a trivial code due to being forced to read the content in the browser to determine what needs to happen and when.
While this is an ok approach, it'll be relatively high maintenance, as these strings can change over time. Also, I wonder how this will work for non-english culture OS-es? Are these strings still in english ?
link.target = '_blank'; | ||
link.rel = 'noopener noreferrer'; | ||
link.click(); | ||
if (isFirefox) { |
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 a lot of Firefox-specific code. Maybe it's worth to move it into a helper function so it's easier to read the logic here:
if (isFirefox)
launchFirefoxDebugger();
else{
...
}
capturedUrl = matchFirefox.Groups["url"].Value; | ||
taskCompletionSource.TrySetResult(capturedUrl); | ||
} | ||
if (isFirefox) |
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.
if the condition in the if
block above has evaluated to true
isn't that already an indication that isFirefox is true
? is there possibility for the check above to evaluate to true
but isFirefox
to be false
?
I'm just trying to see if it's possible to combine these two if
blocks together.
#pragma warning disable CA1835 | ||
static async Task<string> ReceiveMessageLoop(TcpClient browserDebugClientConnect, CancellationToken token) | ||
{ | ||
NetworkStream toStream = browserDebugClientConnect.GetStream(); |
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.
Shouldn't a using
be added to this so the toStream
gets disposed after it's not needed any more?
Which strings? |
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.
Thanks @thaystg !
warningToDebug.style.display = 'none'; | ||
}, 600); | ||
}; | ||
warningToDebug.appendChild(closeWarningButton); |
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 quite a lot of code to include if this is only for displaying an error about debugging. Since we have to include all this code even in production bundles, would it be viable to shrink it? For example we don't need an error to be nicely styled. I think it would be enough even just to use alert(someMessage)
. Or if it's unlikely this ever occurs, we could just console.error(someMessage)
.
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 quite a lot of code to include if this is only for displaying an error about debugging. Since we have to include all this code even in production bundles, would it be viable to shrink it? For example we don't need an error to be nicely styled. I think it would be enough even just to use
alert(someMessage)
. Or if it's unlikely this ever occurs, we could justconsole.error(someMessage)
.
This will probably happen usually, but if you think a console.warning is better for sure I can change it :)
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 ideally prefer to start with something minimal like output to console (or alert
if it's desirable to be visible in the main UI).
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.
Done :)
@@ -12,6 +12,7 @@ | |||
</PropertyGroup> | |||
|
|||
<ItemGroup> | |||
<Reference Include="Newtonsoft.Json" Version="13.0.2" /> |
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.
Could we avoid adding this dependency? Or if there's some reason why System.Text.Json
is insufficient, could you clarify what it is?
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 the same used on BrowserDebugProxy, if you prefer I can try to use System.Text.Json.
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.
Ah, I see, so it won't change the dependencies as far as customers are concerned.
However, having the direct dependency here does mean more dependabot-type noise and TBH it's just really surprising to see Json.NET code show up when we've consistently used STJ elsewhere in this repo. If it's not too disruptive to switch over to STJ for this that would be helpful! If that's impractical or a lot of work let me know.
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.
Removed :)
else if (!string.IsNullOrEmpty(toCmd)) | ||
{ | ||
await SendMessageToBrowser(toStream, JObject.FromObject(new { type = "getWatcher", isServerTargetSwitchingEnabled = true, to = toCmd }), token); | ||
} |
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 this definitely the right way to factor the code? Since debugging-WebAssembly-on-Firefox isn't Blazor-specific (it should ideally be possible even if you're not using Blazor at all), wouldn't it be more applicable to have this code in the runtime library that contains the debug proxy itself?
Apologies if I'm misunderstanding the layering here!
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.
Also alt-shift-d for chrome is not Blazor specific, so this code should also be moved.
I added here to be near to the code that does the same for chrome.
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 don't have a way to get all the tabs available for debugging using a simple request as we do for chrome. We need to use the firefox remote debugging protocol to do it.
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.
OK, up to you to decide the best place for it. If - longer term - we can factor out the non-Blazor-specific parts into a runtime package (presumably BrowserDebugProxy
) that sounds ideal. Would it be worth adding an issue to track that task?
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.
…e the beautiful message, removed the Newtonsoft from the send message, todo: remove the Newtonsoft from receive message.
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.
Thanks for the updates!
…ached to the blazor app (dotnet#46132) * Press alt-shift-d and open firefox debug tab attached to the blazor app * remove debugger.launch. * removing unrelated changes * Removing unnecessary changes on chrome debugging. * addressing @mkArtakMSFT comments * Addressing @mkArtakMSFT comments. * Addressing Steve comments, adding a console.warning message and remove the beautiful message, removed the Newtonsoft from the send message, todo: remove the Newtonsoft from receive message. * Completely removing newtonsoft usage as asked by steve. * Change warning message.
Error if firefox is not opened with remote debugging enabled on port 6000:
![image](https://user-images.githubusercontent.com/4503299/214095094-cbe3618a-479a-4fe1-8e8a-e2c8f1f2bdad.png)
Error if firefox is opened but about:debugging tab is not opened:
![image](https://user-images.githubusercontent.com/4503299/214074481-41a13970-7d1a-4884-b98a-b64fce8d1a6b.png)
Debugging working:
HostedBlazorWebassemblyApp.Mozilla.Firefox.2023-01-17.18-38-33.mp4
The goal of this PR is give the customer a similar experience on firefox that it has when debugging on chrome/edge.
We cannot open automatically the about:debugging tab as we do in chrome/edge for security reasons.
A message is shown on app asking to open about:debugging tab.
Then we connect remotely to this tab and use these functions to configure, connect and open a new tab to debug the blazor app:
I didn't find a way to call await functions using
evaluateJSAsync
from firefox debug protocol, that is why I need some if's before invoke the functions.Related to dotnet/runtime#80722
Fixes dotnet/runtime#80043