Directly copy selected code or files from vscode to a chatgpt tab in browser
VSCode Chatgpt Easy Copy Extension
- How it works?
The vscode extension initializes a websocket server at port 8765 on startup which the chrome extension connects to. On execution of a command, the selected text or contents of file(s) are sent to the chrome extension, via websocket, which manipulates chatgpt's DOM to input in the prompt textarea and send.
More information about the vscode extension can be found at https://github.com/nikhils98/vscode-chatgpt-easy-copy/tree/main/vscode
-- Service Worker
This is where the crux of the logic resides for the chrome extension. It's a background script managing the websocket connection to the vscode extension and responsible for injecting a function to manipulate chatgpt's DOM when a command is received.
It uses chrome's scripting api (https://developer.chrome.com/docs/extensions/reference/api/scripting#description) to inject the function in runtime and requires host permissions for chatgpt to do so. A service worker can become inactive after 30s of idle time so to prevent that a keepalive message is sent to the websocket server every 20s.
In most circumstances, the service worker should be active as long as chatgpt or vscode is running but if it gets inactive at some point, you can try one of the following:
1. Refresh chatgpt tab.
2. Reload the extension from Extensions page. After reload, chatgpt tab must be refreshed as well.
-- Content Script: Ping Server Worker
This runs only when chatgpt is open. It sends a ping message to the service worker every 20s to keep it active when vscode isn't open. Essentially if you open vscode after the service worker had become inactive, opening a tab of chatgpt will make it active again.
- Note:
1. At least one tab of chatgpt must be open. If multiple tabs are open, command is sent to only one.
2. You may see an error related to Websocket connection failure in extension console especially if installed manually. This will be the case when vscode is not running. It can be ignored as the service worker retries connection every second so when you run vscode it should connect.
Source Manifest.json
Similar Extensions
WindChat-ChatGPT Tailwind CSS React Previewer 14 4 ★ 483KiB
Saved Prompts 14 33 ★ 16.47KiB
ChatGPT Extension 14 3 ★ 1.73MiB
Bookmark Folders for ChatGPT 14 16 ★ 140KiB
ChatGPT Chat SAVE 14 9 ★ 12.5KiB
ExportGPT: Export ChatGPT Conversation 14 26 ★ 395KiB
ChatGPT to Markdown 14 22 ★ 117KiB
ChatGPT Cookies 14 1 ★ 67.79MiB
Searchable ChatGPT: search GPT conversation history 14 72 ★ 423KiB
ChatGPT to MarkDown plus 14 21 ★ 37.46KiB
ChatGPT Download For PC, Mac, Windows - Free 14 11 ★ 124KiB
Chat GPT 14 2247 ★ 500KiB
ChatGPT Print and Save 14 4 ★ 4.99MiB
Save ChatGPT to Notion 14 16 ★ 415KiB
ChatGPT to Notion 14 96 ★ 1.65MiB
ChatGPT Folders 14 56 ★ 185KiB
ChatGPT Web Preview 14 7 ★ 456KiB
GPT Booster - ChatGPT File Uploader & Chats Saver 14 22 ★ 3.63MiB
Export ChatGPT - image&Screenshot 14 8 ★ 3.41MiB
Umbrella - Copy All URLs V3 14 0 ★ 364KiB
BookmarkGPT - Bookmark Your ChatGPT Prompts 14 13 ★ 1.68MiB
Whisper to ChatGPT 14 41 ★ 585KiB
ChatGPT File Extension 14 4 ★ 3.91KiB
Save ChatGPT to Obsidian markdown file 14 9 ★ 364KiB