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

Commit

Permalink
Merge pull request #513 from rakatyal/breakonload
Browse files Browse the repository at this point in the history
Adding a landing page to support hitting breakpoints on load
  • Loading branch information
roblourens authored Nov 28, 2017
2 parents f4da852 + d27a7c3 commit 95e5908
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/chromeDebugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export class ChromeDebugAdapter extends CoreDebugAdapter {
private _chromeProc: ChildProcess;
private _overlayHelper: utils.DebounceHelper;
private _chromePID: number;
private _breakOnLoadActive = false;
private _userRequestedUrl: string;

public initialize(args: DebugProtocol.InitializeRequestArguments): DebugProtocol.Capabilities {
this._overlayHelper = new utils.DebounceHelper(/*timeoutMs=*/200);
Expand Down Expand Up @@ -91,6 +93,14 @@ export class ChromeDebugAdapter extends CoreDebugAdapter {
}

if (launchUrl) {
if (args.breakOnLoadStrategy !== 'none') {
// 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;
launchUrl = "about:blank";
this._breakOnLoadActive = true;
}

chromeArgs.push(launchUrl);
}

Expand All @@ -114,6 +124,14 @@ export class ChromeDebugAdapter extends CoreDebugAdapter {
return super.attach(args);
}

public configurationDone(): Promise<void> {
if (this._breakOnLoadActive) {
// 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});
}
return super.configurationDone();
}

public commonArgs(args: ICommonRequestArgs): void {
if (!args.webRoot && args.pathMapping && args.pathMapping['/']) {
// Adapt pathMapping['/'] as the webRoot when not set, since webRoot is explicitly used in many places
Expand Down
2 changes: 1 addition & 1 deletion test/chromeDebugAdapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ suite('ChromeDebugAdapter', () => {
function spawn(chromePath: string, args: string[]): any {
assert(chromePath.toLowerCase().indexOf('chrome') >= 0);
assert(args.indexOf('--remote-debugging-port=9222') >= 0);
assert(args.indexOf('file:///c:/path%20with%20space/index.html') >= 0);
assert(args.indexOf('about:blank') >= 0); // We now launch to about:blank first and then redirect later
assert(args.indexOf('abc') >= 0);
assert(args.indexOf('def') >= 0);
spawnCalled = true;
Expand Down

0 comments on commit 95e5908

Please sign in to comment.