Chrome Extension - injecting javascript fails after download -


i trying download series of files on website using chrome extension. however, after first download, javascript injection fails work.

the following code stripped down version of extension, downloads file page:

http://spreadsheetpage.com/index.php/file/word_clock/

the manifest.json file:

{   "manifest_version": 2,    "name": "file downloader",   "description": "file downloader",   "version": "1.0",     "browser_action": {     "default_icon": "icon.png",     "default_popup": "popup.html"   },   "permissions": [     "tabs",     "activetab",     "http://*/*",     "https://*/*"   ],    "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'" } 

the popup.html file:

<!doctype html> <html>   <head>     <title>file downloader</title> <script src="popup.js"></script>   </head>   <body> file downloader    </body> </html> 

the popup.js file:

function printamessagelater() {     console.log("executed after download initiated");     chrome.tabs.executescript({code: "console.log('executed after download initiated');"}); }  console.log("starting"); chrome.tabs.executescript({code: "console.log('starting');"});  javascriptinjection = "document.evaluate(" + string.fromcharcode(34) + "//a[text()='word clock.xlsm']" + string.fromcharcode(34) + ",document,null,9,null).singlenodevalue.click();";  chrome.tabs.executescript({code: javascriptinjection});  settimeout(function(){printamessagelater()}, 2000); 

the behavior seeing chrome.tabs.executescript({code: "console.log('executed after download initiated');"}); line not result in printed console of page.

my guess download somehow changes focus/context/execution environment (something don't understand) , hence javascript not being injected.

any appreciated.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -