To get selected text with new line characters?

We are developing one Chrome extension. In which we tried to get the selected text in the browser tab using the context menu option and we got an empty string as the selected text using the following method in background.js

window.getSelection().toString()


Then referenced that link and changed the way to get the selected text as

chrome.contextMenus.create({title: "Click", contexts:["selection"], onclick: function(info, tab) { selectedText = info.selectionText; });
Using this method I can able to get the selected text as string ( single line ) with no line breaker. Is it possible to get the selected text with line by line ( with new line characters ) content? Get the text as how it is presented in browser.
For Example:
If this is the content,
Text first line Text second line


I get the selected text as "First line text Second line text". There is no delimiter or any other special characters that end a newline or the end of a line. In my extension, this suggestion will really help.

+3


source to share





All Articles