0

I'm using PageSpeed Insights API from Google Apps Script. Many URLs succeed but some URLs (for example www.google.com) often fail and output the following error.

{ [Exception: Request failed for https://www.googleapis.com returned code 500. Truncated server response: {
  "error": {
    "code": 500,
    "message": "Lighthouse returned error: ERRORED_DOCUMENT_REQUEST. Lighthouse was unable to reliably load the pag... (use muteHttpExceptions option to examine full response)] name: 'Exception' }

My code is just simple as below:

let apiEndpointUrl="https://www.googleapis.com/pagespeedonline/v5/runPagespeed?locale=en_US&url=https://www.google.com&strategy=mobile&key=[MY_KEY]";

const response = UrlFetchApp.fetch(apiEndpointUrl);

And the strangest thing is that when I input the URL(=apiEndpointUrl) to the browser's address bar, it succeeds. Why are the results different between running in GAS and displaying the URL in a browser?

Rubén
  • 34,714
  • 9
  • 70
  • 166
Inclu Cat
  • 354
  • 1
  • 12
  • A web browser besides being able to execute JavaScript, it's able, among other things, to run several Web APIs. Google Apps Script hasn't this posibilities by default. – Rubén May 01 '22 at 17:22
  • Possible duplicate: https://stackoverflow.com/q/69904021/1595451 – Rubén May 01 '22 at 17:24
  • Thanks, but I can't understand how the post you gave relates to my problem. I don't want to know how to use API by Javascript, but want to know **WHY** using the API by Javascript **sometimes** fails. (even though it succeeds every time in my browser) – Inclu Cat May 02 '22 at 00:51

0 Answers0