I'm making chrome extension to access to webpage DOM as Grammarly like when the user clicks on the word I want to store it, I wrote some code on the content script, but it only works when I click on the extension popup.
My code content script:
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
const console = {
log: (info) => chrome.extension.getBackgroundPage().console.log(info),
};
chrome.tabs.executeScript(
tabs[0].id,
{
code: "window.getSelection().toString();",
},
(result) => {
console.log(result);
}
);
});
as you see when I open the extension popup it then shows the selected word, so my question is how can I get the word as clicking without opening the popup like Grammarly.