lighthouse icon indicating copy to clipboard operation
lighthouse copied to clipboard

[Pagespeed API] Support custom user agent in pagespeed API

Open avastu opened this issue 7 years ago • 8 comments

Pagespeed exhibits bot like behavior which can get caught by our bot detection mechanisms, preventing us from measuring pagespeed. I'd like to request the addition of a custom user agent param for pagespeed to use. We can then whitelist the specified user agent to allow pagespeed to run correctly. Alternatively, if you could provide the network blocks from which the pagespeed is run, we can whitelist those.

Provide the steps to reproduce

  1. Visit https://developers.google.com/speed/pagespeed/insights/?url=https%3A%2F%2Fwww.redfin.com

What is the current behavior?

Page can show an error saying: Lighthouse returned error: ERRORED_DOCUMENT_REQUEST. Lighthouse was u nable to reliably load the page you requested. Make sure you are testing the correct URL and that the server is properly responding to all requests. (Status code: 403) (It may not error out all the time. We've temporarily whitelisted the block 66.249.84.0/24, but I believe that block is used for more than just page speed.)

What is the expected behavior?

Pagespeed runs without an error.

Environment Information

avastu avatar Mar 26 '19 22:03 avastu

necessarily-wide-alpaca

avastu avatar Mar 26 '19 22:03 avastu

sorry about that @avastu, overaggressive bot detection mechanism here :)

brendankenny avatar Mar 26 '19 22:03 brendankenny

PSI does include Chrome-Lighthouse in the request User-Agent. Is that sufficient to filter for?

brendankenny avatar Mar 26 '19 23:03 brendankenny

No worries! I didn't know about that, it should be--thank you! Is that user agent documented anywhere?

avastu avatar Mar 26 '19 23:03 avastu

Is that user agent documented anywhere?

I don't believe so, but it's part of the requesting infrastructure, so it won't be changing.

cc @paulirish

brendankenny avatar Mar 27 '19 00:03 brendankenny

I was just wondering if there's somewhere I could have looked before creating this issue. Let me know if you'd like me to add documentation about it!

avastu avatar Mar 27 '19 17:03 avastu

PSI does include Chrome-Lighthouse in the request User-Agent. Is that sufficient to filter for?

Jumping in the conversation (hopefully relevant) given it's still Open.

Thought the Chrome-Lighthouse is provided, it would be nice to be able to add additional User-Agent parts. Now, as far as I could see from here and here it should be actually possible to do that.

But, if I look at the generated json, I cannot find any trace of the additional part I added. To be fair, I still haven't tested it from the server-side part - but I suppose that additional User-Agent parts should also be displayed in the json from lighthouseResult > environment> networkUserAgent.

Or am I doing / getting something wrong?

angelogulina avatar Jun 13 '19 16:06 angelogulina

If you need to identify that its a Lighthouse pageload that you initiated, consider adding a special URL param.

Also, you can always clone Lighthouse and run the CLI locally with whatever changes you want. :)

paulirish avatar Apr 28 '20 20:04 paulirish