-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Conversation
/cc @zhangsu |
/cc @choumx |
There was a problem hiding this 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return true;
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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. 😄
There was a problem hiding this comment.
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')) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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')) { |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
report-errors-to-viewer
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this 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> |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, sorry about that.
…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
…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
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.