Loading a local html file in an injected iframe within a firefox extension

吃可爱长大的小学妹 提交于 2019-12-04 16:58:31

I'm assuming the usage of the Addon SDK, that is more similar to Google Chrome extensions development, than the regular XUL development in Firefox. However, the approach I'm explaining here works also without the Add-on SDK.

In Add-on SDK is not currently possible, but there is some working about it, see Bug 820213.

The only workaround that comes to my mind at the moment, is using data: url. So, instead having:

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

Notice the data.load instead of data.url: you basically load the content of the resource and use that as data url. It's ugly but at least can be used in some cases until a proper fix.

Hope it helps!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!