-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
20 lines (20 loc) · 814 Bytes
/
Copy pathbackground.js
File metadata and controls
20 lines (20 loc) · 814 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === "fetchPageText") {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
chrome.scripting.executeScript(
{
target: { tabId: tabs[0].id },
function: () => document.body.innerText
},
(results) => {
if (results && results[0] && results[0].result) {
sendResponse({ text: results[0].result });
} else {
sendResponse({ text: "No text found on this page." });
}
}
);
});
return true; // Required for async response
}
});