3

Hello Firefox Addon SDK experts,

I'm pretty badly stuck with the following issue.

From my content script, I need to draw a UI using a set of HTML files and image files that are stored under my add-on's Data directory.

I fetch the file URLs in main.js using self.data.url and pass the URLs to content script using port.emit. The URLs are successfully received by the content script.

When I log URL of data/html/myfile.html in content script, it looks like this: resource://jid1-veokemuf24jrmw-at-jetpack/myaddon/data/html/myfile.html

The problem is that nothing seems to happen when I append the element in the document like this:

var a = this;
a.el = $("<div />").attr("id", "topbar");
$("body").append(a.el);
$("#topbar").load(html_url, function() {});

But if I copy-paste the html code from the file to the content script then it works.

Also, if I paste the html file URL to the Firefox's address field it's opened ok.

Is there some fundamental thing why my solution can't work? Or maybe, do I need to define some permission for my add-on to make files under Data directory to be accessible from content script?

All help is highly appreciated.

mikko76
  • 115
  • 1
  • 5
  • Is the html displayed in a Panel? Also, fyi any resources referred to in an html file loaded from data can use relative urls, eg if you have index.html, it can refer to an image in the same directory via ./some-image.png – therealjeffg May 29 '13 at 17:45
  • Thanks for the quick reply canuckistani. No, it's not in a Panel. The html is added in the page through page-mod. See, my add-on injects some JavaScript to the page in order to draw some additional UI on top of the current page. Now I'm already able to make an image (png) to be loaded and drawn in the page, so the add-on's Data folder content obviously is accessible from the content script. Now it's just that JQuery.load() doesn't do anything. No exception, just nothing happens. – mikko76 May 30 '13 at 05:33
  • I found out that JQuery.load gives the following error inside a parameter (xhr.statusText) of the callback function: "Access to restricted URI denied" (code 1012). Now I'm trying to find out if there is anything I can do about it. – mikko76 May 30 '13 at 06:30
  • not sure, maybe the resource uri isn't available to web content? – therealjeffg Jun 03 '13 at 04:02
  • or, especially, jquery.load might expect an http url, not a resource uri – therealjeffg Jun 03 '13 at 19:36
  • Thanks for your thoughts canuckistani! I gave up and put the HTML content in our server. Now I've got a whole different issue with Fancybox and content script. In case you are curious: http://stackoverflow.com/questions/16977627/firefox-add-on-sdk-iframe-in-content-script-how-to-communicate-with-main-js – mikko76 Jun 07 '13 at 06:33
  • possible duplicate of [Get content of some file in Firefox SDK main.js](http://stackoverflow.com/questions/29783153/get-content-of-some-file-in-firefox-sdk-main-js) – e-motiv Sep 07 '15 at 16:11
  • That should answer the question if you are using Add-On SDK : http://stackoverflow.com/questions/21082162/firefox-addon-sdk-loading-addon-file-into-iframe – Emmanuel Sellier Oct 07 '15 at 09:34
  • Possible duplicate of [Firefox Addon SDK: Loading addon file into iframe](http://stackoverflow.com/questions/21082162/firefox-addon-sdk-loading-addon-file-into-iframe) – Paul Sweatte Jan 18 '17 at 16:37

1 Answers1

0

I gave up and put the HTML content in our server. Now I've got a whole different issue with Fancybox and content script.

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265