Note that there are some explanatory texts on larger screens.

plurals
  1. POgetting error window.getselection() --- developing chrome extension
    primarykey
    data
    text
    <p>I am developing a chrome extension , i need to get selected text from any page to chrome extension.I am unable to get the output </p> <p>I just want to take selected image or any text to extension</p> <p>In console getting the following error</p> <p>Uncaught IndexSizeError: Index or size was negative, or greater than the allowed value. </p> <pre><code>//script.js var selection = window.getSelection(); var range = selection.getRangeAt(0); //Getting error in this line.window.getSelection() is always null if (range) { var div = document.createElement('div'); div.appendChild(range.cloneContents()); vs=div.innerHTML; } chrome.extension.sendRequest({viewsource: vs}, function(response) { console.log(response.farewell); }); chrome.tabs.executeScript(null, {file:"script.js"}); chrome.extension.onRequest.addListener( function(request, sender, sendResponse) { document.getElementById("txtar").innerText=request.viewsource; }); //popup.html &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;script type="text/javascript" src="script.js"&gt;&lt;/script&gt; &lt;style&gt; body { margin:0px; padding:0px; overflow:hidden; background:pink; } #txtar { height: 200px; width: 300px; max-width:780px; max-height:560px; min-width:300px; min-height:200px; padding:6px; margin:0px; background-color:white; color:#000088; border:none; } #boohle { position:absolute; bottom:0px; left:0px; font-size:10px; font-family:Arial; float:left; background-color:white; z-index:200; font-weight:normal; } #boohle a { color:#008800; text-decoration:none; } #boohle a:hover { color:#ff0000; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;textarea id="txtar" readonly&gt;&lt;/textarea&gt; &lt;/body&gt; &lt;/html&gt; //manifest.json { "name": "Selection", "version": "1.0", "browser_action": { "default_icon": "img/19x19.png", "default_title": "View Selection Source", "default_popup": "popup.html" }, "manifest_version": 2, "description": "View selection source in resizable popup. Drag the bottom right corner to resize. Simple, but very useful for web developers.", "icons": { "128": "img/128x128.png", "16": "img/16x16.png", "19": "img/19x19.png", "32": "img/32x32.png", "48": "img/48x48.png" } } </code></pre> <p>Please help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload