* Query local or fetch remote author script. * * Returns promise that resolves with the script contents or rejected if the * fetch fails or if the script fails CORS checks. * * Returns null if script reference is missing. * * @param {string} debugId An element identifier for err
(debugId)
| 395 | * @private |
| 396 | */ |
| 397 | getAuthorScript_(debugId) { |
| 398 | const authorUrl = this.element.getAttribute('src'); |
| 399 | if (authorUrl) { |
| 400 | return this.fetchAuthorScript_(authorUrl, debugId); |
| 401 | } else { |
| 402 | const id = this.element.getAttribute('script'); |
| 403 | if (id) { |
| 404 | const local = this.getAmpDoc().getElementById(id); |
| 405 | userAssert( |
| 406 | local, |
| 407 | '[%s] %s could not find element with #%s.', |
| 408 | TAG, |
| 409 | debugId, |
| 410 | id |
| 411 | ); |
| 412 | const target = local.getAttribute('target'); |
| 413 | userAssert( |
| 414 | target === 'amp-script', |
| 415 | '[%s] script#%s must have target="amp-script".', |
| 416 | TAG, |
| 417 | id |
| 418 | ); |
| 419 | const text = local.textContent; |
| 420 | if (this.development_ || this.sandboxed_) { |
| 421 | return Promise.resolve(text); |
| 422 | } else { |
| 423 | return this.service_.checkSha384(text, debugId).then(() => text); |
| 424 | } |
| 425 | } |
| 426 | } |
| 427 | // No [src] or [script]. |
| 428 | return null; |
| 429 | } |
| 430 | |
| 431 | /** |
| 432 | * @param {string} authorUrl |
no test coverage detected