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

Enable break-on-load breakpoints #445

Closed
auchenberg opened this Issue Jun 19, 2017 · 9 comments

Comments

Projects
None yet
4 participants
@auchenberg
Contributor

auchenberg commented Jun 19, 2017

Currently we aren't able to break in code running immediately as a part of a page load, as we attached to Chrome while the page is loading, which creates a timing issue. This means that we can't hit some breakpoints.

Workarounds:

  • Set the breakpoint, and refresh the page.

Potential solutions:

  • Implement a "breakOnLoad" option that issues a page-refresh after first attach.

Things to consider
For further versions of the feature it might be worth consider some minor edge cases, for example if you want to debug the first time a web-page is loaded because either the web-server or the web-page itself have side-effects like setting a cookie, or modifying a database, and you may have issues that only reproduce the first time the web-page is loaded. For those scenarios, the refreshOnLoad solution wouldn’t work, and something like the Regexp can help.

The other potential issue with refreshOnLoad is that it’ll only make breakpoints work for scripts that were already loaded on the page. Some web-pages may load new scripts after you press a button, or take another action, and if you refresh before those scripts are loaded, then refreshOnLoad won’t make those breakpoints hit the first time you use that feature

@auchenberg

This comment has been minimized.

Show comment
Hide comment
@auchenberg

auchenberg Jul 26, 2017

Contributor

I've opened an issue in the Chrome tracker, https://bugs.chromium.org/p/chromium/issues/detail?id=749153

Contributor

auchenberg commented Jul 26, 2017

I've opened an issue in the Chrome tracker, https://bugs.chromium.org/p/chromium/issues/detail?id=749153

@auchenberg

This comment has been minimized.

Show comment
Hide comment
@auchenberg

auchenberg Jul 31, 2017

Contributor

After chatting with the Chrome team there might be a way as Chrome supports scriptFirstStatement breakpoints via DOMDebugger.setInstrumentationBreakpoint, which will pause execution on every newly loaded script.

We could enable scriptFirstStatement, wait for scriptParsed, set breakpoints in paused file` and resume execution afterwards as an experiment. The start/stop overhead might be too much.

// Prevent code being executed
cdp.sendCommand("DOMDebugger.setInstrumentationBreakpoint", {
  eventName: "scriptFirstStatement"
});

// Enable Debugger domain to receive its events
cdp.sendCommand("Debugger.enable");

cdp.addListener("message", (event, method, params) => {
  // Script is ready to be edited
  if (method === "Debugger.scriptParsed") {
    cdp.sendCommand("Debugger.setScriptSource", {
      scriptId: params.scriptId,
      scriptSource: `console.log("edited script ${params.url}");`
    }, (err, msg) => {
      // After editing, resume code execution.
      cdg.sendCommand("Debugger.resume");
    });        
  }
});

Ping @roblourens, @dlebu, @digeff

Contributor

auchenberg commented Jul 31, 2017

After chatting with the Chrome team there might be a way as Chrome supports scriptFirstStatement breakpoints via DOMDebugger.setInstrumentationBreakpoint, which will pause execution on every newly loaded script.

We could enable scriptFirstStatement, wait for scriptParsed, set breakpoints in paused file` and resume execution afterwards as an experiment. The start/stop overhead might be too much.

// Prevent code being executed
cdp.sendCommand("DOMDebugger.setInstrumentationBreakpoint", {
  eventName: "scriptFirstStatement"
});

// Enable Debugger domain to receive its events
cdp.sendCommand("Debugger.enable");

cdp.addListener("message", (event, method, params) => {
  // Script is ready to be edited
  if (method === "Debugger.scriptParsed") {
    cdp.sendCommand("Debugger.setScriptSource", {
      scriptId: params.scriptId,
      scriptSource: `console.log("edited script ${params.url}");`
    }, (err, msg) => {
      // After editing, resume code execution.
      cdg.sendCommand("Debugger.resume");
    });        
  }
});

Ping @roblourens, @dlebu, @digeff

@roblourens

This comment has been minimized.

Show comment
Hide comment
@roblourens

roblourens Jul 31, 2017

Member

That's really interesting, I wonder what the overhead is like.

Member

roblourens commented Jul 31, 2017

That's really interesting, I wonder what the overhead is like.

@auchenberg

This comment has been minimized.

Show comment
Hide comment
@auchenberg

auchenberg Jul 31, 2017

Contributor

We should try to prototype this, and see if the overhead is significantly less than the solution @digeff did for VS.

Contributor

auchenberg commented Jul 31, 2017

We should try to prototype this, and see if the overhead is significantly less than the solution @digeff did for VS.

@digeff

This comment has been minimized.

Show comment
Hide comment
@digeff

digeff Jul 31, 2017

Contributor

I think that is the command we used originally, and it had a bug with external html references or something like that. @dlebu Do you remember what was the issue?

Contributor

digeff commented Jul 31, 2017

I think that is the command we used originally, and it had a bug with external html references or something like that. @dlebu Do you remember what was the issue?

@dlebu

This comment has been minimized.

Show comment
Hide comment
@dlebu

dlebu Aug 1, 2017

Member

The issue was a hang with Chrome while loading the page for the first time, which blocked some of our customers in VS. If you decide to go this route, I can provide a sample page to test and see if this reproduces in the VS Code environment as well.

Member

dlebu commented Aug 1, 2017

The issue was a hang with Chrome while loading the page for the first time, which blocked some of our customers in VS. If you decide to go this route, I can provide a sample page to test and see if this reproduces in the VS Code environment as well.

@auchenberg

This comment has been minimized.

Show comment
Hide comment
@auchenberg

auchenberg Aug 1, 2017

Contributor

Thanks @dlebu. I have re-created the issue here where Chrome doesn't seem to resume execution when using HTML imports. https://github.com/auchenberg/chrome-break-on-load

I'll open a bug for the Chrome team.

Contributor

auchenberg commented Aug 1, 2017

Thanks @dlebu. I have re-created the issue here where Chrome doesn't seem to resume execution when using HTML imports. https://github.com/auchenberg/chrome-break-on-load

I'll open a bug for the Chrome team.

@auchenberg

This comment has been minimized.

Show comment
Hide comment
@auchenberg
Contributor

auchenberg commented Aug 2, 2017

@auchenberg

This comment has been minimized.

Show comment
Hide comment
@auchenberg
Contributor

auchenberg commented Dec 8, 2017

@auchenberg auchenberg closed this Dec 8, 2017

@vscodebot vscodebot bot locked and limited conversation to collaborators Mar 29, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.