Using PageSpeed Insights API from GAS makes error

192 views Asked by At

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?

0

There are 0 answers