Firefox Addon SDK: Loading addon file into iframe

后端 未结 3 1433
猫巷女王i
猫巷女王i 2020-12-09 13:52

I want to load a resource:// link, respectively a local file from my Firefox addon into an iframe in a web page.

The reason is, that the re

3条回答
  •  感动是毒
    2020-12-09 14:05

    I'm using zer0's idea. However, on pages with a content-security-policy I got an exception (...result = 2153644038). For that reason, I add my domain to the content-security-policy of the response header:

    //main.js 
    var { Cc, Ci } = require('chrome');
    
    var observer = {
        observe : function(aSubject, aTopic, aData) {
          if (aTopic == "http-on-examine-response") {
            aSubject.QueryInterface(Ci.nsIHttpChannel);
            var csp = aSubject.getResponseHeader("content-security-policy");
            if(csp.indexOf('frame-src') > -1) {
                var cspParts = csp.split(';');
                for (var i=0; i -1) {
                        cspParts[i] += ' yourdomain.tld';
                        break;
                    }
                }
                aSubject.setResponseHeader("content-security-policy", cspParts.join(';'), false);
            } 
          }
        }
    }; 
    var observerService = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
    observerService.addObserver(observer, "http-on-examine-response", false);
    
    //content-script.js 
    iframe.src = yourdomain.tld/...
    

    EDIT: This code might be rejected by a FF reviewer with: "Modifying 'content-security-policy' is not allowed for security reasons."

提交回复
热议问题