Have you ever wondered how the Bing chat sidebar in the Edge browser works? Let's discover it through reverse engineering! 🧵
First, it's important to note that the chat interface inside the sidebar is actually a web page. This allows us to inspect it using developer tools.
The page is embedded through an iframe in two layers: the built-in "discover-chat" page contains a "shell" page, which in turn contains the "chat" page (or the "compose" page).
So how does this web page obtain information about the currently browsed page? This web page must communicate with the browser in some way.
As it turns out, the "chat" page and "discover-chat" page exchange messages via window.postMessage
When users visit a url or switch tabs, the browser sends a `TabStripModelChange` message to the chat page, so it learns about the current viewing page. Then it will try to get the cotent of the web page via the followin ways:
1. Request an API called `/sydneyzeroturn` with the web page url, which returns the text content of the web page. I suspect this is fetched from the Bing search engine crawled data.
2. Sometimes the above API returns empty content for the web page, perhaps because the page hasn't been crawled, the chat page will request the content by sending a `Page.GetData` message to the browser. The browser will send back the text content it renders for the web page.
Then when you chat with Bing about the web page, Bing will send the full text content of the current page to the conversation API. And AI will answer your question based on the context you provided.
That's all, we now know why the sidebar Bing chat can chat about the current web page!
Based on the above knowledge, I've built a browser extension that replicates the Bing sidebar in Chrome, you can install it at: https://t.co/S9LHWDPqGYchrome.google.com/webstore/detai…
@threadreaderapp unroll
• • •
Missing some Tweet in this thread? You can try to
force a refresh