Can't read response content in devtools.network.onRequestFinished callback

311 views
Skip to first unread message

Wang Dàpéng

unread,
Jul 12, 2023, 7:28:14 AM7/12/23
to Chromium Extensions
I'm trying to inspect the response of ChatGPT SSE api with this code:

chrome.devtools.network.onRequestFinished.addListener((request) => {
  const headers = request.response.headers;
  const header = headers.find((header) => header.name === "content-type");
  if (header?.value.includes("text/event-stream")) {
    request.getContent((content, encoding) => {
      log(JSON.stringify({ content, encoding }));
    });
  }
});

But content is always null.

You can reproduct it with this repo: https://github.com/wong2/sse-inspector
Install the extension, send message in chat.openai.com

wOxxOm

unread,
Jul 12, 2023, 7:44:13 AM7/12/23
to Chromium Extensions, Wang Dàpéng
Do you see a non-empty response for this exact request in devtools UI? If not, the site may be using a WebSocket connection.

Wang Dàpéng

unread,
Jul 12, 2023, 8:22:40 AM7/12/23
to Chromium Extensions, wOxxOm, Wang Dàpéng
The devtools UI also shows empty response, but I can explain it.
This is because ChatGPT web app is not using the built-in `EventSource` api to send SSE requests, instead it's using the `fetch` api, so devtools does not parse the response.
Does request.getContent have the same behavior as devtools UI?
But claude.ai have a different behavior...I can get the content with the above code, but the devtools UI is also empty.

wOxxOm

unread,
Jul 12, 2023, 9:00:22 AM7/12/23
to Chromium Extensions, Wang Dàpéng, wOxxOm
Indeed, chrome.devtools API is using the same backend as devtools itself, so a matching behavior is what I'd expect here as well.
Reply all
Reply to author
Forward
0 new messages