Using Devtool/Puppeteer to simulate 103 Early Hints

502 views
Skip to first unread message

Debin Zhang

unread,
Dec 5, 2023, 10:26:03 AM12/5/23
to Chromium-dev
Hi,

Is this possible to use Devtool or Puppeteer to send 103 Early Hints packages to browser? This is to simulate web server or CDN provider to send 103 Early Hints packages to browser. It is for testing purpose only, so that we do not need to modify web server and CDN settings to generate new 103 Early Hints.

Thanks

Debin

Alex Rudenko

unread,
Dec 5, 2023, 10:32:09 AM12/5/23
to Chromium-dev, Debin Zhang
Hi Debin,

it should be possible to use request interception to craft a 103 response when needed. It can be done with Puppeteer https://pptr.dev/guides/request-interception
DevTools also offers a way to override responses https://developer.chrome.com/docs/devtools/overrides/ but I am not sure it would work for http status codes.

Best regards,
Alex

Debin Zhang

unread,
Dec 5, 2023, 1:56:55 PM12/5/23
to Chromium-dev, Alex Rudenko, Debin Zhang
Hi Alex,

Thank you for your quick reply.

Because I am trying to simulate 103 Early Hints, when I receive the root request I immediately send an Early Hint response to the browser by calling request.respond(), then the code tries to continue, hoping the request would be forwarded to the web server and get a reply back as usual. But I got the "Request is already handled! exception" because request.respond() has already been called. The issue is mentioned in this link: https://pptr.dev/guides/request-interception.

Does anyone know if is possible to workaround this restriction that a request can only handled once or send multiple responses to a single request? Essentially, I want to simulate 103 Early Hints in our test environment. Any solution would be acceptable.

Thanks!!!

Debin

Alex Rudenko

unread,
Dec 5, 2023, 4:37:11 PM12/5/23
to Chromium-dev, Debin Zhang, Alex Rudenko
I am afraid it is only possible specify a single response for the interception AFAIK. 

Debin Zhang

unread,
Dec 8, 2023, 10:17:19 AM12/8/23
to Chromium-dev, Alex Rudenko, Debin Zhang

Do you know if this "one-request-one-response" restriction is introduced by Puppeteer, or it is from Chrome DevTools Protocol (CDP)? Is this possible to modify Chromium and Puppeteer to workaround this?

Thanks

Debin

Message has been deleted

Debin Zhang

unread,
Dec 13, 2023, 12:12:08 PM12/13/23
to Chromium-dev, Debin Zhang, Alex Rudenko
Alex,

My team needs a way to experiment with different Early Hints. I wonder if it is possible to add an InjectEarlyHints parameter to this page.navigation CDP method. This InjectEarlyHints parameter could be an object that includes a list of link hints and it can include the number of milliseconds to wait before injecting. When present, Chromium would wait the specified number of milliseconds and invoke its early hint handling functions. Do you think it is possible to make such a modification in the CDP protocol?

Thank you in advance.

Debin

Noam Rosenthal

unread,
Dec 18, 2023, 3:47:05 PM12/18/23
to debin...@gmail.com, Chromium-dev, Alex Rudenko
On Wed, Dec 13, 2023 at 5:12 PM Debin Zhang <debin...@gmail.com> wrote:
Alex,

My team needs a way to experiment with different Early Hints. I wonder if it is possible to add an InjectEarlyHints parameter to this page.navigation CDP method. This InjectEarlyHints parameter could be an object that includes a list of link hints and it can include the number of milliseconds to wait before injecting. When present, Chromium would wait the specified number of milliseconds and invoke its early hint handling functions. Do you think it is possible to make such a modification in the CDP protocol?

Anything stopping you from doing that using a local server instead of a Chromium API? It would likely be more robust.
Reply all
Reply to author
Forward
0 new messages