Help get this topic noticed by sharing it on Twitter, Facebook, or email.

Creating and interacting with iframes

I would like to be able to do the following two things:

1) Create an iframe on a page, where src points to a resource file.
2) Within this iframe, communicate with the background scripts.

Is this even possible in crossrider. If so how would i do this.
1 person has
this question
+1
Reply
  • Shlomo (Official Rep) April 09, 2015 06:14
    Hello Scott,

    Extensions built using the Crossrider platform can uses resource files but they cannot be referenced directly. Thus, in answer to your first question, from the extension.js file you can inject an iframe to a page and use the iframe srcdoc attribute to supply the HTML from a resource file using appAPI.resources.get. For example:
    $('<iframe srcdoc="'+appAPI.resources.get('iframe.html')+'"></iframe>')
    .appendTo('body');
    By default, the extension.js file only runs on top-level frame and hence not in iframes. However, there is an option on the Settings page to Run in iframes. Once enabled, the extension.js file also runs in iframes (though some browsers do no permit this with injected iframes).

    Communicating between an extension instance running on an iframe and the background scope is a little tricky as it cannot be done directly with the background scope. Hence, the communication must use the iframe's parent as a go between with the background scope using the appAPI.message methods. Note that you can differentiate between instances running in top-level frames and iframes using appAPI.dom.isIframe.

    In short, it's not a simple task but may be achievable. You can try implementing and testing the outline provided and feel free to ask questions if you need any assistance.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited

  • This approach does not my needs for several reasons:

    1) My entire source would have to be within srcdoc, which is doable, but undesirable.
    2) These new iframes would not have a common domain, and so they could not share local storage.
    3) Information would leak by passing messages through the parent element. Since I am writing a security focused extension this is not acceptable.

    Are there any plans to ever support this functionality in crossrider? I know that Kango can do this, as I have a working prototype of it doing so. I did have to modify the Firefox add on code to allow it as by default you can't point iFrames to a resource:// url, but otherwise it works great. I would love to see this in crossrider and could certainly share that piece of code if it would be helpful.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited