1

Here's a minimal GitHub Gist that runs on Electron Fiddle :

Electron Fiddle

It's supposed to show GitHub Copilot (github.com/copilot) in a webview element as if it was in a normal browser :

GitHub Copilot in normal browser, working fine

Using the following code :

const webviewSession = session.fromPartition(`persist:${id}`); // <- `id` === 'githubCopilot', pointing to element `<webview partition="persist:githubCopilot"></webview>`
webviewSession.protocol.handle('https', request => new Promise(async resolve => {
  const response = await net.fetch(request, { bypassCustomProtocolHandlers: true });
  resolve(response);
}));

I'm intercepting the requests with the intent of doing something later, notably logging SSE chunks, but for now I want it working while doing nothing more.

However, after logging in, the chat history never loads :

GitHub Copilot in Electron, chat history doesn't load

I noticed there was a request that was failing with HTTP 422 :

POST github.com/copilot/agent-sessions/token returns 422

Which return 200 in a normal browser :

POST github.com/copilot/agent-sessions/token returns 200

Any idea what could be wrong here, considering I'm not even transforming the requests at all yet ?

Here's the code I will add for logging SSE below resolve(response) (already tested and working on a different website that uses SSE) :

if(response.headers.get('content-type') === 'text/event-stream'){
const
    reader = response.clone().body.getReader(),
    decoder = new TextDecoder();
while(true){
    const { done, value } = await reader.read();
    if(done) break;
    const text = decoder.decode(value, { stream: true });
    console.log({ text });
}

Whatever solution works for the primary issue should also either remain compatible with this or have an alternative for it.

Please don't mention AI, it always either suggests webviewSession.protocol.interceptStreamProtocol which is deprecated, or webviewSession.webRequest.filterResponseData which doesn't exist at all.

Thanks

2
  • One could argue, that the webview tag itself is deprecated these days. Is there a reason why you don't use a WebContentsView instead? Commented Nov 8 at 14:56
  • In practice, I have multiple webview elements that I conditonally make (in)visible using a tabbed interface powered by Vue. The Fiddle example is just a minimal version using only one. The useless-looking for loop is a remnant of that multi-webview config actually. Anyways, would doing that switch solve my issue anyway ? Commented Nov 8 at 16:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.