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 the error reporting logic through the AMP Viewer #12986

Merged
merged 8 commits into from
Jan 31, 2018
Merged

Implement the error reporting logic through the AMP Viewer #12986

merged 8 commits into from
Jan 31, 2018

Conversation

raywainman
Copy link
Contributor

@raywainman raywainman commented Jan 23, 2018

Implement the error reporting logic through the AMP Viewer

Fixes #12950.

Passes errors to the AMP Viewer if the following is true:
-The viewer is in single document mode
-The viewer is trusted
-The viewer has the errorReporter capability
-The document is opted-in for error interception, this can be done by adding an additional attribute called allow-error-reporting-to-viewer in the <html> tag.

The client embedding the AMP viewer can then use these errors for their own monitoring or reporting.

The error passed to the viewer is the same as the error passed to the AMP error server.

@raywainman
Copy link
Contributor Author

/cc @zhangsu

@zhangsu
Copy link
Member

zhangsu commented Jan 23, 2018

/cc @choumx

Copy link

@dreamofabear dreamofabear left a comment

Choose a reason for hiding this comment

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

Just a few minor comments. Thanks for contributing this!

src/error.js Outdated
return Promise.resolve();
}
viewer.sendMessage('error', data);
return Promise.resolve(true);

Choose a reason for hiding this comment

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

return true;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

src/error.js Outdated
*
* @param {!JsonObject} data Data from `getErrorReportData`.
* @return {!Promise<boolean|undefined>} True if the error was sent to the
* viewer, `Promise<undefined>` otherwise.

Choose a reason for hiding this comment

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

How about resolve with false to make this signature a bit simpler?

src/error.js Outdated
* viewer, `Promise<undefined>` otherwise.
* @visibleForTesting
*/
export function maybeReportErrorToViewer(data) {

Choose a reason for hiding this comment

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

Minor: Can we add the window as a param and pass it in through the caller (which uses this instead of self)?

maybeReportErrorToViewer(win, data)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, done.

src/error.js Outdated
const ampdocSingle = ampdocService.getAmpDoc();
const htmlElement = ampdocSingle.getRootNode().documentElement;
const docOptedIn =
htmlElement.hasAttribute('allow-error-reporting-to-viewer');

Choose a reason for hiding this comment

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

Bike-shed: report-errors-to-viewer? I'll also solicit suggestions in our weekly communal bike-shed tribunal. 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hehe sounds good, I like report-errors-to-viewer!

src/error.js Outdated
}

const viewer = Services.viewerForDoc(ampdocSingle);
if (!viewer.hasCapability('errorReporter')) {

Choose a reason for hiding this comment

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

Tangent: I don't see this updated in the internal viewer docs yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right this is ongoing on our end. Dropped you a note about this.

src/error.js Outdated

return viewer.isTrustedViewer().then(viewerTrusted => {
if (!viewerTrusted) {
return Promise.resolve();

Choose a reason for hiding this comment

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

Minor: Just directly return the value here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

src/error.js Outdated
*
* @param {!JsonObject} data Data from `getErrorReportData`.
* @return {!Promise<boolean|undefined>} True if the error was sent to the
* viewer, `Promise<undefined>` otherwise.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

src/error.js Outdated
* viewer, `Promise<undefined>` otherwise.
* @visibleForTesting
*/
export function maybeReportErrorToViewer(data) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, done.

src/error.js Outdated
const ampdocSingle = ampdocService.getAmpDoc();
const htmlElement = ampdocSingle.getRootNode().documentElement;
const docOptedIn =
htmlElement.hasAttribute('allow-error-reporting-to-viewer');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

hehe sounds good, I like report-errors-to-viewer!

src/error.js Outdated

return viewer.isTrustedViewer().then(viewerTrusted => {
if (!viewerTrusted) {
return Promise.resolve();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

src/error.js Outdated
return Promise.resolve();
}
viewer.sendMessage('error', data);
return Promise.resolve(true);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

src/error.js Outdated
}

const viewer = Services.viewerForDoc(ampdocSingle);
if (!viewer.hasCapability('errorReporter')) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right this is ongoing on our end. Dropped you a note about this.

@@ -15,7 +15,7 @@
This demonstrates that certain attributes are not allowed on the root <html> element.
-->
<!doctype html>
<html ⚡ allow-xhr-interception>
<html ⚡ allow-xhr-interception allow-error-reporting-to-viewer>

Choose a reason for hiding this comment

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

report-errors-to-viewer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, sorry about that.

@@ -16,7 +16,9 @@ FAIL
| This demonstrates that certain attributes are not allowed on the root <html> element.
| -->
| <!doctype html>
| <html ⚡ allow-xhr-interception>
| <html ⚡ allow-xhr-interception allow-error-reporting-to-viewer>

Choose a reason for hiding this comment

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

report-errors-to-viewer here and below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor Author

@raywainman raywainman left a comment

Choose a reason for hiding this comment

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

Thanks!

@@ -16,7 +16,9 @@ FAIL
| This demonstrates that certain attributes are not allowed on the root <html> element.
| -->
| <!doctype html>
| <html ⚡ allow-xhr-interception>
| <html ⚡ allow-xhr-interception allow-error-reporting-to-viewer>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -15,7 +15,7 @@
This demonstrates that certain attributes are not allowed on the root <html> element.
-->
<!doctype html>
<html ⚡ allow-xhr-interception>
<html ⚡ allow-xhr-interception allow-error-reporting-to-viewer>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, sorry about that.

@dreamofabear dreamofabear merged commit 2cdc9d3 into ampproject:master Jan 31, 2018
RanAbram pushed a commit to RanAbram/amphtml that referenced this pull request Mar 12, 2018
…t#12986)

* error reporting to the AMP viewer

* add trusted viewer checks for the error reporting

* address error log pull review comments

* remove redundant line in error test

* validator feature test for new allow-error-reporting-to-viewer attribute

* fix presubmit errors

* address pull request comments fo the error reporting capability

* update testdata files to reflect new capability
protonate pushed a commit to protonate/amphtml that referenced this pull request Mar 15, 2018
…t#12986)

* error reporting to the AMP viewer

* add trusted viewer checks for the error reporting

* address error log pull review comments

* remove redundant line in error test

* validator feature test for new allow-error-reporting-to-viewer attribute

* fix presubmit errors

* address pull request comments fo the error reporting capability

* update testdata files to reflect new capability
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants