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

Implement OnLoadingFailed in CDP #156

Merged
merged 1 commit into from
Apr 28, 2017
Merged

Conversation

sarvaje
Copy link
Contributor

@sarvaje sarvaje commented Apr 21, 2017

No description provided.

@sarvaje
Copy link
Contributor Author

sarvaje commented Apr 25, 2017

@molant @alrra I think this PR is ready to review :)

@@ -17,5 +19,8 @@
<body>
<h1>Common collector test page</h1>
<p>The content of this HTML is used to validate that all collectors that parse full HTML send the same events.</p>
<p>These two images are to test that we are not entering in a infinite loop when we have more than one element with the same src or href</p>
<img src='http://localhost/edge.png'/>
Copy link
Member

Choose a reason for hiding this comment

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

By default jsdom doesn't download images unless we have the canvas package (at least with v10). We should look into adding it.

https://github.com/tmpvar/jsdom#loading-subresources

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test is just for CDP. In jsdom we don't have that problem

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe I can add into the message that those images are for testing in CDP collector

Copy link
Member

Choose a reason for hiding this comment

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

It was more a comment rather than something you should do now.
We will have to do it for some of the tests, probably when we update to v10 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ahh ok :)

@@ -94,6 +94,11 @@ class CDPCollector implements ICollector {
return elements[0];
}

if (parts.length === 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this if be taken care of in the last line of the while? If there is something wrong with that then we should:

  • Move this if to the top of the while.
  • Replace the comment with the one from the bottom:

/* If we reach this point, we have several elements that have the same url so we return the first
because its the one that started the request. */

  • Remove the return elements[0] at the end.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@molant I'll try to refactor the code to exit the while with it condition, not with that if

// TODO: implement this for `fetch::error` and `targetfetch::error`.
console.error(params);
private async onLoadingFailed(params) {
// DOM is not ready so we queued up the event for later
Copy link
Member

Choose a reason for hiding this comment

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

// DOM is not ready so we queue up the event for later

return;
}

/* If the requestId is not in this._requests then that means that we already process the
Copy link
Member

Choose a reason for hiding this comment

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

/* If requestId is not in this._requests it means that we already processed the request in onResponseReceived */

* request in onResponseReceived
*/
if (!this._requests.has(params.requestId)) {
debug(`requestId doesn't exits skipping this error`);
Copy link
Member

Choose a reason for hiding this comment

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

`requestId doesn't exist, skipping this error

return;
}

debug(`Error found: ${JSON.stringify(params)}`);
Copy link
Member

Choose a reason for hiding this comment

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

debug(Error found:\n${JSON.stringify(params)});

@@ -105,6 +105,11 @@ export class Requester {
return Requester.charsetAliases.get(results[1]) || results[1];
}

/** Return the redirects for a given `uri` */
Copy link
Member

Choose a reason for hiding this comment

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

/** Return the redirects for a given uri. */

@@ -27,6 +27,8 @@ export interface IFetchErrorEvent {
element: IAsyncHTMLElement;
/** The error found. */
error: any;
/** The hop for the url */
Copy link
Member

Choose a reason for hiding this comment

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

/** The redirects performed for the url. */

*
* We need to add here the `fetch::error` ones
*/
/** The minimum set of events the collectors need to implement */
Copy link
Member

Choose a reason for hiding this comment

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

/** The minimum set of events the collectors need to implement. */

resource: 'http://localhost/script4.js',
request: { url: 'http://localhost/script4.js' },
response: {
body: {
Copy link
Member

Choose a reason for hiding this comment

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

I think you can remove body, and hops. If a property doesn't exist we ignore it when testing.

@@ -238,6 +278,13 @@ const testCollector = (collectorBuilder: ICollectorBuilder) => {
invokes.push(emitAsync.getCall(i).args);
}

/* We need to test that there was just a fetch::error */
Copy link
Member

Choose a reason for hiding this comment

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

// We test there was just a single fetch::error emitted

Fix infinete loop when there is two or more elements with an absolute path in the dom
Fix the data we send in JSDOM when an error happens
@sarvaje
Copy link
Contributor Author

sarvaje commented Apr 28, 2017

@molant conflicts resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants