can you write a simple chrome extension that will save the content of a chatgpt…
- User
can you write a simple chrome extension that will save the content of a chatgpt conversation
- Assistantjavascript
// manifest.json { "manifest_version": 3, "name": "ChatGPT Saver", "version": "1.0", "description": "Saves the content of a ChatGPT conversation.", "permissions": [ "activeTab", "storage" ], "action": { "default_popup": "popup.html" } } // popup.html <!DOCTYPE html> <html> <head> <title>ChatGPT Saver</title> </head> <body> <h1>Save ChatGPT Conversation</h1> <button id="saveBtn">Save</button> <script src="popup.js"></script> </body> </html> // popup.js document.getElementById('saveBtn').addEventListener('click', () => { chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { chrome.scripting.executeScript({ target: { tabId: tabs[0].id }, function: saveConversation }); }); }); function saveConversation() { // Get the conversation content from the ChatGPT page const conversation = document.querySelector('.conversation-container').innerHTML; // Save the conversation to Chrome storage chrome.storage.local.set({ conversation: conversation }, () => { alert('Conversation saved!'); }); }Explanation:
-
manifest.json:
- Defines the extension's metadata (name, version, description).
- Requests permissions to access the active tab and Chrome storage.
- Specifies the popup HTML file (
popup.html).
-
popup.html:
- A simple HTML page with a button to trigger the saving process.
- Includes the
popup.jsscript.
-
popup.js:
- Listens for a click on the "Save" button.
- Uses
chrome.tabs.queryto get the active tab.
-
- User
can you extend the extension code to save the conversation in html that looks similar to what is shared in the conversation
- Assistantjavascript
- User
does this include the css
- Assistant
No, the code provided only saves the content of the ChatGPT conversation without including the CSS styles. If you want to save the entire ChatGPT conversation page, including the CSS styles, you can modify the code as follows:
javascript// manifest.json (no changes) // popup.html (no changes) // popup.js document.getElementById('saveBtn').addEventListener('click', () => { chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { chrome.scripting.executeScript({ target: { tabId: tabs[0].id }, function: saveConversation }); }); }); function saveConversation() { // Get the entire ChatGPT page content chrome.tabs.captureVisibleTab(null, { format: 'png' }, (dataUrl) => { // Save the data URL to Chrome storage chrome.storage.local.set({ conversation: dataUrl }, () => { alert('Conversation saved!'); }); }); }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.