1

I'm trying to make my extension create an iframe which its src tag direct to an svg file which is located at the extension files. something like <iframe src="chrome://trail/content/onpagegui.svg"></iframe>

Whenever I do it I get the following error: Security Error: Content at http://... may not load or link to chrome://trail/content/onpagegui.svg. (I think that's cause of the same origin policy)

I tried all kind of ways to solve this problem, among them I tried to use resource: instead of chrome: as suggested at How can a Firefox extension inject a local css file into a webpage? but I can't make it work either cause I'm trying to embed an svg instead of a css or because I just don't get it... btw as much as I understood from MDC, resource: is for javascript codes and not css, am I right? is this solution workable?

I also tried to build the entire iframe and svg just by javascript, that cause tons of other issues to appear...

Is there any way to embed that .svg file into the newly created iframe?

Thanks a lot in advance, Yonatan

2 Answers 2

0

You need to make your extension contentaccessible.

2
  • Currently @ manifest.chrome I got the following line: ` content trail chrome/content/ contentaccessible=yes ` Sadly it doesn't work, I do know that the contentaccessible flag is being called correctly since I rely on it at other parts of my extension... Mar 6, 2011 at 9:32
  • Ah, that's interesting, I didn't realise that contentaccessible didn't apply to frames. Sorry about that.
    – Neil
    Mar 6, 2011 at 23:49
0

I can think of two possible solutions:

  1. Use e.g. XMLHttpRequest to read your SVG into a string. Then set the src of the frame to a data: URL.
  2. Register a component that implements nsIAboutModule. Then set the src of the frame to your custom about: URL.

Ironically neither of these methods requires contentaccessible!

6
  • ok I had time only to test the first option and it works but only partially, from some reason the svg is getting loaded and work as supposed to but its css code is totally ignored... (everything is just black). Oh btw, in order to read the SVG content into a string I used nsIScriptableInputStream instead of XMLHttpRequest, nothing wrong with that right? Will test the second option asap and will let u know about the results (got some other things on my head as well...). Mar 9, 2011 at 16:10
  • I just tried to implement your second suggestion but I keep failing to create an about: url (used the descriptions at the url u gave), more then that I found this thread forums.mozillazine.org/… where the first reply state that this page is not for extensions at all (or am I misunderstanding something here?). I actually want to make an about: url even for another issue at my extension. thx again :) Mar 14, 2011 at 14:12
  • OK I finally managed to make the about: url work (interesting enough I didn't do a thing.... extremely bizarre), anyhow it gives the same result as the first solution, the svg is getting loaded but only in black.... my guess is that it doesn't understand its doctype, though y not if it's basically the same file? Mar 14, 2011 at 17:49
  • btw I found that setting the src to be the svg file at a remote server it work as it should (http://...). very bizarre... Mar 14, 2011 at 18:46
  • Accessing remote SVG has fewer concerns since the developers are more used to dealing with remote sites trying to access content from other remote sites, and therefore are more likely to try to get things to work safely rather than blocking content to play safe.
    – Neil
    Mar 14, 2011 at 23:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.