Skip to content
This repository has been archived by the owner on Dec 6, 2022. It is now read-only.

Adding a landing page to support hitting breakpoints on load #513

Merged
merged 2 commits into from
Nov 28, 2017

Conversation

rakatyal
Copy link
Contributor

No description provided.

@@ -86,6 +87,10 @@ export class ChromeDebugAdapter extends CoreDebugAdapter {
}

if (launchUrl) {
// We store the launch file/url provided and temporarily launch and attach to about:blank page. Once we receive configurationDone() event, we redirect the page to this file/url
// This is done to facilitate hitting breakpoints on load
this._originalUrl = launchUrl;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rename this to requestedUrl or userRequestedUrl or something like that

@auchenberg
Copy link
Contributor

Why would we always navigate to about:blank and trigger another page load?

@rakatyal
Copy link
Contributor Author

@auchenberg: Chrome needs a url to start a debug session. When we specify the target url here, it may load the page first sometimes before all the setBreakpoints requests are received. For this reason we may miss hitting breakpoints on load. So as a workaround, we now start the debug session with "about:blank" and then navigate to the target url once all the setBreakpoints requests are completed.

@auchenberg
Copy link
Contributor

@rakatyal We will only need this for the regex-based break-on-load breakpoints and only in the case of breakpoints set before launching, right? We should only extra work such as an extra page.navigate when it's needed.

@@ -111,6 +116,12 @@ export class ChromeDebugAdapter extends CoreDebugAdapter {
return super.attach(args);
}

public configurationDone(): Promise<void> {
// This means all the setBreakpoints requests have been completed. So we can navigate to the original file/url.
this.chrome.Page.navigate({url: this._userRequestedUrl});
Copy link
Member

Choose a reason for hiding this comment

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

This means all the requests have been sent, but not necessarily handled by the adapter. I'm not sure if that's an issue or not. Should this be waiting for us to finish handling the initial setBreakpoints?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean by not handled by the adapter? As long as Chrome receives all the requests before we navigate we should be good. Wouldn't that be the case here?

Copy link
Member

@roblourens roblourens Oct 25, 2017

Choose a reason for hiding this comment

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

I guess so? I'm just wondering whether it would be a problem if we do something like

  • Get setBreakpoints
  • Send lots of setBreakpoint requests to Chrome
  • Don't get responses yet from Chrome
  • Tell Chrome to navigate

Maybe Chrome will finish processing the set breakpoint requests before it actually navigates. Or maybe there could be a race case where it could load the new page before it's actually set the breakpoints, I'm not sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm. Is there a way where we can be sure that Chrome has finished processing those requests?

Copy link
Member

Choose a reason for hiding this comment

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

All I can think of is waiting on the responses from Chrome. But I think this is similar to what we do in node2 already, and I don't wait before doing a 'continue' and it's never caused a problem. So I think this is fine for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good!

@@ -88,6 +89,10 @@ export class ChromeDebugAdapter extends CoreDebugAdapter {
}

if (launchUrl) {
// We store the launch file/url provided and temporarily launch and attach to about:blank page. Once we receive configurationDone() event, we redirect the page to this file/url
// This is done to facilitate hitting breakpoints on load
this._userRequestedUrl = launchUrl;
Copy link
Member

Choose a reason for hiding this comment

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

Like @auchenberg said this should only be if breakOnLoad is enabled for 'regex'.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay I was trying to solve this and it didn't work as expected as I thought and the page loaded without hitting any breakpoints. I think if we don't wait for the navigation problem can be 2 fold:

  1. Chrome can actually load the page before receiving the setInstrumentationBreakpoint request at all.
  2. Since in order to hit those breakpoints, we need Chrome to receive all the setBreakpoints requests anyway so that they are stored in the pendingBreakpoints array which I use to resolve the breakpoints when Chrome stops the execution on the first line.

So I think we will have to use this in both the cases for "regex" and "instrument" and not use it when it's "none"

Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be fair, we can write code to basically not use pendingBreakpoints and call setBreakpoints after we stop on the scripts just for the "instrument" case but I believe it would be complicating stuff. Also in this case, I am only setting instrumentation breakpoint when setBreakpoint is called (or when user actually has a breakpoint before launch) and not in all cases. So due to this reason too, we need to have this landing page or else we need to figure out some other way to set the instrumentation point.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah it does make sense that we need to do this in both cases, either we are setting the BPs via regex or we are setting the Instrumentation BP.

@rakatyal
Copy link
Contributor Author

@auchenberg: Good point. I will update the PR.

@rakatyal
Copy link
Contributor Author

@roblourens: Updated the PR with the change to navigate only when break on load strategy is not 'none'

@roblourens roblourens merged commit 95e5908 into microsoft:master Nov 28, 2017
@roblourens roblourens added this to the December 2017/January 2018 milestone Feb 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants