-
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
JavaScript validation API - get validation result #1967
Comments
@Gregable Are you comfortable with declaring the existing API public or should we expose something from AMP? |
Yes. I commented on this here: #999 (comment) You can also build the validator from github. There are already instructions here: https://github.com/ampproject/amphtml/tree/master/validator |
@Gregable: thanks for the fiddle in #999. So to validate the current document, one would inject this: result = amp.validator.validateString(document.head.innerHTML + document.body.innerHTML) The problem is I see vastly different results between the console message and the result of the code above. For example, these URLs display
Similarly, when the console shows "AMP validation had errors", |
If you are using:
On a document like:
Then the string being evaluated will be roughly:
Which is missing significant parts of the document, so the validator will emit more errors. |
I'd recommend doing an XHR to the doc (and get the direct string) to On Tue, Feb 16, 2016 at 10:15 PM, Greg Grothaus notifications@github.com
|
@Gregable: Duh, silly me. @cramforce: I think this is faster and as complete: document.documentElement.outerHTML Does the |
@dandv The problem is that the mechanism doesn't catch stuff like <script>
document.write('whatever');
document.body.removeChild(document.currentScript);
</script> which is invalid AMP but might pass your validator. |
Here's a code snippet that would allow one to get the result for validation using XHR. One can also get the specific warnings/errors from the result as well via result.errors.
|
I think the solutions here are probably sufficient. We now also have http://npmjs.org/amphtml-validator and https://validator.ampproject.org/ which are probably what most people will use. |
Is there a way to get the result of the validation when the page is loaded with
#development=1
?I've poked around the
amp
object but all properties and functions seem to be or return null. Even this:returns
null
when run at http://carnaval.uol.com.br/2016/album/2016/02/05/bloco-das-carmelitas-desfila-pelas-ruas-de-santa-teresa-no-rio-de-janeiro.htm?amp#development=1, before errors are output to the console.amp.validator.errors
andamp.validator.ValidationResult()
arenull
before and after callingvalidateUrlAndLog
.Usable return values would allow headless browsers to extract the validation result into a variable, making automation in-situ possible, without needing to use #937.
The text was updated successfully, but these errors were encountered: