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

New: Added Chrome Traces to cdp connector #420

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/lib/connectors/shared/remote-debugging-connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ export class Connector implements IConnector {
/** Initiates all the process */
private onLoadEventFired(callback: Function): Function {
return () => {
const { DOM } = this._client;
const { DOM, Tracing } = this._client;
const event: IEvent = { resource: this._finalHref };

setTimeout(async () => {
Expand All @@ -548,6 +548,15 @@ export class Connector implements IConnector {
await this.getFavicon((await this._dom.querySelectorAll('link[rel~="icon"]'))[0]);
}

await new Promise((resolve) => {
Tracing.tracingComplete(() => {
this._server.emitAsync('tracing::end', event);
resolve();

});
debug(`Ending Collecting Chrome traces`);
Tracing.end();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can Tracing.end throw an exception? if so, you can wrap it in a try/catch and call to reject in the catch

Copy link
Author

Choose a reason for hiding this comment

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

I think Tracing.end would throw just as Page.navigate or other chrome commands would. This just sends the command over to chrome over the protocol, so IMHO, it should be fine.

});
await this._server.emitAsync('scan::end', event);

// We are going to wait until all the requests are finished or this._options.maxLoadWaitTime seconds before finish
Expand Down Expand Up @@ -597,7 +606,7 @@ export class Connector implements IConnector {
}

this._client = client;
const { Page, Security } = client;
const { Page, Security, Tracing } = client;

// Bypassing the "Your connection is not private"
// certificate error when using self signed certificate
Expand Down Expand Up @@ -625,6 +634,11 @@ export class Connector implements IConnector {

try {
await this.configureAndEnableCDP();
Tracing.dataCollected((data) => {
this._server.emitAsync('tracing::data', { data, resource: event.resource });
});
debug(`Starting collecting Chrome Traces`);
await Tracing.start();

await Page.navigate({ url: target.href });
} catch (e) {
Expand Down