I want to firstly understand what is content script and what is background page in extension development.
is the content Script the script which is in website content? the background page is extensions html page?
i am asking this because i want to send the selected text to a webservice in this way:
I have two problems here:
1) how do I get the selected text to show in the menu instead of ''
, window.getSelection().toString()
is showing nothing
2) how can I send this text to django backend.
here are my attemps:
function onClickHandler(info, tab) {
var selectedtext = info['selectionText'];
//how to send this text to django backend?
};
chrome.contextMenus.onClicked.addListener(onClickHandler);
chrome.runtime.onInstalled.addListener(function() {
var contexts = ["selection"];
for (var i = 0; i < contexts.length; i++){
var context = contexts[i];
var title = "Send the word '" + window.getSelection().toString() + "' to django backend";
var id = chrome.contextMenus.create({"title": title, "contexts":[context],"id": "context1" + context});
}
});