Loading local html file in iframe increment within Firefox extension

I am currently developing a firefox extension that basically inserts an iframe on the current page when the user clicks on the extension's icon. I was able to insert the iframe code, I figured out how to bind the src attribute to my html file.

In the chrome version I just do

 var main_html = chrome.extension.getURL('main.html');

      

And I pass the link to the src attribute of the iframe like this:

 iframe.setAttribute("src",main_html);

      

So main_html is a link as resource: //idofmyextension/content/data/main.html

But as I suspected, I received a security error message informing me that the content located at the current url cannot load data or set a link to my main.html file.

Is there a way to pass this security limitation? Or another way to load my html file in my iframe?

Thanks in advance.

+2


source to share


1 answer


I am assuming using the Addon SDK , which is more like developing Google Chrome extensions than normal XUL development in Firefox.However, the approach I am explaining here also works without the Add-on SDK.

Not currently available in the Add-on SDK, but some of them work, see Bug 820213 .

The only workaround that comes to my mind at the moment is using data:

url. So instead of this:

const { data } = require("self");

let url = data.url("main.html");

// pass the url to the iframe

      



You will have:

const { data } = require("self");

let content = encodeURIComponent(data.load("main.html"));
let url = "data:text/html;charset=utf-8," + content;

// pass the url to the iframe

      

Note the data.load

instead data.url

: you are basically downloading the content of the resource and using it as the data url. This is ugly, but at least can be used in some cases until it is properly fixed.

Hope it helps!

+3


source







All Articles