Note that there are some explanatory texts on larger screens.

plurals
  1. POChrome Extension: Communication iframe <-> Content Script
    primarykey
    data
    text
    <p>Well, a often discussed thing. But I can't get it work. What has to be done:</p> <ul> <li>The Content or Background Script has to communicate with the iframe et vice versa.</li> <li>The iframe is under my hand, so there is everything possible.</li> </ul> <p>I tried a lot. It doesn't work at all. For instance: If I deploy the content script on every page with allFrames=true via (manifest). Ok, makes sense. The iframe is created later so the trigger won't be called. So let's do this: create the iframe and afterwards sending an executeScript request:</p> <pre><code> chrome.tabs.executeScript(tabinst.tab_id, { allFrames: true, file:'frame.js'}, function() { console.log("done"); }); </code></pre> <p>But that doesn't work either. Has anyone a solution to communicate with an XDM iframe and a chrome extension?</p> <p>PS: How nice it would be if the chrome extension would allow postMessage on iframe</p> <p><strong>EDIT1:</strong></p> <p>The code doesn't get injected in the iframe. Scenario:</p> <p>The file "file.js" has a simple foo function in it. I now apply it with the above statement 2 seconds after the iframe was created and showed. This function foo is not available in the iframe...but is in the content script. The ReferenceError is thrown by trying to execute foo within the iframe (by click).</p> <p>So, it's not a timing thing. And it doesn't matter if I apply the Scripts via manifest and all_frames true. If that would work, the content_script would be available. But is not.</p> <p><strong>EDIT2:</strong> @serg</p> <p>Yeah, thanks, that works! I just got through it. My problem was, that I assumed that when the callback of chrome.tabs.executeScript is called, the requested script is ended and the including DOM manipulation finished. But that's actually not the case. It takes some time till the script in the iframe and the containing listener is ready.</p> <p>So I had to send a chrome.extension.sendRequest from that script in the iframe and then start some code out of the background listener to manipulate the iframe. Thanks for your help.</p> <p>PS: It's also possible to do it without "all_frames": true. It just takes some time till the dynamic iframe is ready. With a timeout it works. For the most cases, this is not useful, but maybe someone has another user interaction first.</p> <p>PPS: I still can't see why it's possible like this, and not possible to send postMessage events. But maybe somewhen this will works.</p>
    singulars
    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.
 

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