Possible duplicate:
Creating a Chrome extension - entering code on a page using script content
Below is my initial attempt. First I created a test webpage:
- test.html -
<HTML> <SCRIPT src="script.js"></SCRIPT> </HTML>
- script.js -
function testFunction() { console("function successfully run!"); }
Then I created a very simple extension to see if I can run testFunction () from the contents of the script:
- manifest.json -
{ "name": "Function Test", "manifest_version": 2, "version": "1", "description": "An extension to experiment with running the javascript functions of the website being browsed.", "permissions": ["<all_urls>"], "content_scripts": [ { "all_frames": true, "matches": ["<all_urls>"], "js": ["cs.js"], "run_at": "document_end" } ] }
- cs.js -
scriptNodes = document.getElementsByTagName("script"); script = scriptNodes[0]; console.log(script.src); script.testFunction();
Here is the console output:
file:
So, is it possible to run the function on the website you are viewing using the Chrome extension?
source share