Skip to content

<amp-script>: Fix and improve error messages for script hash #29614

@morsssss

Description

@morsssss

There are a few things here!

Changed amp.dev link

The error message currently says, See https://amp.dev/documentation/components/amp-script/#security-features.​​​. In fact, in #29487, we changed this link to See https://amp.dev/documentation/components/amp-script/#script-hash.​​​

Can we update the link in error messages?

Incorrect message for incorrect script hash

If you happen to get the script hash for <amp-script> wrong, you might expect to get an error message that says something like, Script hash for <amp-script> is incorrect. You must include <meta name="amp-script-src" "sha384-...">

Instead, what you see is this:

amp-script Script hash not found. amp-script[script="user-agent-script"].js must have "sha384-2pF8pO53GSTphKniorRl5ubWFfal7Bwf7_jBq8_r-SaaoT14q0gAOBzro5gndckK" in meta[name="amp-script-src"].

This situation can easily happen - if you update your inline JavaScript, you'll get this error unless you're also using tooling to update the hash.

Using that wording for missing script hash, too

I wouldn't have requested this change independently, but if you like the wording above, you might want to use something similar for a missing script hash. Like:

Script hash for <amp-script> is missing. You must include <meta name="amp-script-src" "sha384-...">

Or:

<amp-script>: Missing script hash. You must include <meta name="amp-script-src" "sha384-...">

Uncaught error

It would also be DX-positive if this error was caught, so the developer didn't see an additional error in the console, like this:

image

/cc @samouri , @sebastianbenz

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions