I'm building a firefox extension which intercepts a page load for a certain domain and returns it's own HTML instead. The issue I'm having is that once I've intercepted the page and returned the html, I can't seem to add a page-worker to allow the script to communicate back to the higher-privileged extension code. If there's a way to communicate back without a page-worker that'd be good too. Here's my code:
var { Class } = require('sdk/core/heritage');
var { Unknown } = require('sdk/platform/xpcom');
var { Cc, Ci, Cr, Cu } = require('chrome')
var observerService = Cc['@http://ift.tt/1efiEYk'].
getService(Ci.nsIObserverService);
var data = require("sdk/self").data;
var pageWorkers = require("sdk/page-worker");
Cu.import("resource://gre/modules/Services.jsm");
var TOPIC_MODIFY_REQUEST = 'http-on-modify-request';
var StartObserver = Class({
extends: Unknown,
interfaces: [ 'nsIObserver' ],
topic: '*',
register: function register() {
observerService.addObserver(this, this.topic, false);
},
unregister: function() {
observerService.removeObserver(this, this.topic);
},
observe: function observe(subject, topic, observeData) {
//console.log('star observer:', subject, topic, data);
if (TOPIC_MODIFY_REQUEST == topic) {
subject.QueryInterface(Ci.nsIHttpChannel);
let url = subject.URI.spec;
if(!url.indexOf("https://example.com")) {
subject.redirectTo(Services.io.newURI("data:text/html,"+data.load("intercept.html"), null, null));
//This is not adding the page-worker
pageWorkers.Page({
contentURL: "https://example.com",
contentScriptFile: [data.url("inject.js")],
contentScriptWhen: "start"
});
}
}
}
});
exports.Intercept = function(){
var startobserver = StartObserver();
startobserver.register();
};
Aucun commentaire:
Enregistrer un commentaire