0

I have a simple Chrome extension which injects content_script into pages found at certain URLs. I am trying to use the injected JS to call a function which is already defined within a frame of the original page (to piggyback on its functionality).

I have tried using window.frames['framename'].functionname('arg'); but that doesn't seem to work with the injection, but it would work if I were entering that directly into console. Similarly, attempting to call functionname() directly doesn't seem to work. I know the javascript itself is injecting because once the page is loaded I have been able to set myscript.js to alert("test"); which works correctly, but if I attempt to call the functions I either get "not defined" or "not a function" errors in console. Looking at the console it seems that ['framename'] and ('arg') are being sanitised out of the javascript.

I have been searching for a while now to try and find a way to resolve this, but without any luck. Any ideas?

MANIFEST

 {
// Required
"manifest_version": 2,
"name": "My Extension",
"version": "0.1",

"content_scripts": [
 {
 "matches": ["URL"],
 "js": ["myscript.js"],
 "run_at": "document_end",
 "all_frames": true

 }]

 }

EDIT: Solved with Method 1 over here: Insert code into the page context using a content script

Sorry about the duplicate.

Community
  • 1
  • 1
  • 1. [Insert code into the page context using a content script](//stackoverflow.com/a/9517879) 2. Beware you can directly access iframe.contentWindow only for same-origin frames. – wOxxOm Apr 15 '17 at 12:28
  • @wOxxOm this is a bit of a newbie question, but is it considered better etiquette to delete duplicate questions or to keep them and reference the original answer? – CursingLoudlyintheOffice Apr 15 '17 at 12:34

0 Answers0