Chrome Extension get selected text

You can use the last expression evaluated by the executed code in a callback function:

chrome.tabs.executeScript( {
  code: "window.getSelection().toString();"
}, function(selection) {
  document.getElementById("output").value = selection[0];
});

Leave a Comment