Here's a complete Chrome extension that summarizes all text on the current page. This implementation uses Manifest V3 (Chrome's latest standard) and includes a basic text summary (first 200 characters). You can expand the summarization logic later.
🔧 Step 1: Create Project Structure
Create a folder named text-summarizer-extension and add these files:
text-summarizer-extension/
│
├── manifest.json
├── popup.html
├── popup.js
├── content.js
└── icon.png
📄 manifest.json
{
"manifest_version": 3,
"name": "Text Summarizer",
"version": "1.0",
"description": "Summarizes all text on the current page.",
"permissions": ["activeTab", "scripting"],
"host_permissions": ["<all_urls>"],
"action": {
"default_popup": "popup.html",
"default_icon": "icon.png"
},
"background": {
"service_worker": "background.js"
},
"content_scripts": [{
"matches": ["<all_urls>"],
"js": ["content.js"]
}]
}
📄 popup.html
<!DOCTYPE html>
<html>
<head>
<title>Summary</title>
<style>
body {
width: 300px;
padding: 10px;
font-family: Arial, sans-serif;
}
#summary {
white-space: pre-wrap;
font-size: 14px;
}
</style>
</head>
<body>
<h3>Summary</h3>
<div id="summary">Loading...</div>
<script src="popup.js"></script>
</body>
</html>
📄 popup.js
function summarizeText(text) {
const maxLength = 200;
if (text.length <= maxLength) {
return text;
}
return text.substring(0, maxLength) + "...";
}
// Get the active tab and send a message to the content script
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
const tab = tabs[0];
chrome.tabs.sendMessage(tab.id, { action: "getText" }, function (response) {
if (response && response.text) {
document.getElementById("summary").innerText = summarizeText(response.text);
} else {
document.getElementById("summary").innerText = "No text found.";
}
});
});
📄 content.js
// Listen for messages from the popup
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
if (request.action === "getText") {
// Extract all text from the page
const text = document.body ? document.body.innerText : "No text found.";
sendResponse({ text: text });
}
});
🖼️ icon.png
Add a 16x16 or 32x32 pixel PNG icon (you can use any image or generate one).
✅ How to Use
- Open Chrome.
- Go to
chrome://extensions/.
- Enable Developer Mode.
- Click Load unpacked and select your
text-summarizer-extension folder.
- Navigate to any webpage and click the extension icon.
- The popup will show a summary of the text on the page (first 200 characters).
🚀 Optional Enhancements
- Better Summarization: Replace the
summarizeText function with a more advanced algorithm (e.g., splitting by sentences).
- API Integration: Use a backend or external API (like Hugging Face or Google's NLP) for real summaries.
- UI Improvements: Add a "Copy Summary" button or toggle between full text and summary.
This code is soup-to-nuts and ready to use. Let me know if you want to add advanced features!