javascript - Copy Data from webpage chrome extension -


i trying copy data webpage , using

window.getselection().tostring(); 

works fine in cases, if there frame or fancy site or trying copy google hangout(inside gmail), won't copy selected , tried document.getselection no luck. 1 know other way can copy data webpage ?. full code this

chrome.tabs.executescript(tab.id, {code: 'var datatosend;datatosend= window.getselection().tostring(); ' +'chrome.runtime.sendmessage({ text: datatosend });'}); 

any appreciated.

update added minimal code re create issue background.js

function genericonclick(info, tab)  {   chrome.tabs.executescript(tab.id, {       code: 'var datatosend;datatosend=\"\";datatosend= window.getselection().tostring(); ' +           'chrome.runtime.sendmessage({ text: datatosend });'   });   chrome.runtime.onmessage.addlistener(function (msg) {     if (msg.text !== undefined) {       alert(msg.text);       }   }); }  var title = "my menu"; chrome.contextmenus.create({"title": title, "contexts":["selection"],"onclick": genericonclick}); 

manifest.json

{   "name"                   : "test copy",   "version"                : "0.1",   "manifest_version" : 2,   "permissions"            : [     "contextmenus",     "tabs",     "activetab"   ],   "background"             : {     "scripts"    : ["background.js"]   },   "content_scripts"        : [{     "matches"    : ["http://*/*", "https://*/*"],     "js"         : ["background.js"],     "run_at"     : "document_end",     "all_frames" : true   }] } 

it works in site won't work sites frames http://help.autodesk.com/cloudhelp/2015/enu/maya-tech-docs/commandspython/

chrome.tabs.query({       "active": true,       "currentwindow": true           }, function (tabs) {         chrome.tabs.sendmessage(tabs[0].id, {           "functiontoinvoke": "getselecteddatafrompage"         });       });   chrome.runtime.onmessage.addlistener(function (msg) {     if (msg.seltext !== undefined && msg.seltext != "") {       copytonext(msg.seltext);       }   }); 

from background script send content_script , inside content script window.getselection works because can add all_frame true works every where.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -