Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5961703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:00:09+00:00 2026-05-22T19:00:09+00:00

I’ve been reading and hacking around with https://developer.mozilla.org/en/XUL_School/Intercepting_Page_Loads but can seem to do what

  • 0

I’ve been reading and hacking around with https://developer.mozilla.org/en/XUL_School/Intercepting_Page_Loads but can seem to do what I need.

I’m working on Chromeless, trying to prevent the main xulbrowser element from ever being navigated away from, e.g., links should not work, neither should window.location.href="http://www.example.com/".

I’m assuming I can do this via browser.webProgress.addProgressListener and then listen to onProgressChange but I can’t figure out how to differentiate between a resource request and the browser changing locations (it seems that onLocationChange is too late as the document is already being unloaded).

browser.webProgress.addProgressListener({
    onLocationChange: function(){},
    onStatusChange: function(){},
    onStateChange: function(){},
    onSecurityChange: function(){},
    onProgressChange: function(){
        aRequest.QueryInterface(Components.interfaces.nsIHttpChannel)
        if( /* need to check if the object triggering the event is the xulbrowser */ ){
            aRequest.cancel(Components.results.NS_BINDING_ABORTED);
        }
    },
    QueryInterface: xpcom.utils.generateQI([Ci.nsIWebProgressListener, Ci.nsISupportsWeakReference])
}, wo._browser.webProgress.NOTIFY_ALL);

Another option that sounds promising is the nsIContentPolicy.shouldLoad() method but I really have no clue how to “create an XPCOM component that extends nsIContentPolicy and register it to the “content-policy” category using the nsICategoryManager.”

Any Ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T19:00:09+00:00Added an answer on May 22, 2026 at 7:00 pm

    I got help on this from the mozilla’s #xulrunner irc channel.

    Resulting solution follows.

    Note: this is a module for use in Mozilla Chromeless, the require("chrome") and require("xpcom") bits will NOT be available under normal circumstances.

    const {Cc, Ci, Cu, Cm, Cr} = require("chrome");
    
    const xpcom = require("xpcom");
    
    /***********************************************************
    class definition
    ***********************************************************/
    
    var description = "Chromeless Policy XPCOM Component";
    /* UID generated by http://www.famkruithof.net/uuid/uuidgen */
    var classID = Components.ID("{2e946f14-72d5-42f3-95b7-4907c676cf2b}");
    // I just made this up. Don't know if I'm supposed to do that.
    var contractID = "@mozilla.org/chromeless-policy;1";
    
    //class constructor
    function ChromelessPolicy() {
        //this.wrappedJSObject = this;
    }
    
    // class definition
    var ChromelessPolicy = {
    
      // properties required for XPCOM registration:
      classDescription: description,
      classID:          classID,
      contractID:       contractID,
      xpcom_categories: ["content-policy"],
    
      // QueryInterface implementation
      QueryInterface: xpcom.utils.generateQI([Ci.nsIContentPolicy,
        Ci.nsIFactory, Ci.nsISupportsWeakReference]),
    
      // ...component implementation...
      shouldLoad : function(aContentType, aContentLocation, aRequestOrigin, aContext, aMimeTypeGuess, aExtra) {
        let result = Ci.nsIContentPolicy.ACCEPT;
        // only filter DOCUMENTs (not SUB_DOCUMENTs, like iframes)
        if( aContentType === Ci.nsIContentPolicy["TYPE_DOCUMENT"]
            // block http(s) protocols...
            && /^http(s):/.test(aContentLocation.spec) ){
            // make sure we deny the request now
            result = Ci.nsIContentPolicy.REJECT_REQUEST;
        }
        // continue loading...
        return result;
      },
      createInstance: function(outer, iid) {
        if (outer)
            throw Cr.NS_ERROR_NO_AGGREGATION;
        return this.QueryInterface(iid);
      }
    };
    
    let registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
    try
    {
        Cm.nsIComponentRegistrar.registerFactory(classID, description, contractID, ChromelessPolicy);
    }
    catch (e) {
        // Don't stop on errors - the factory might already be registered
        Cu.reportError(e);
    }
    
    const categoryManager = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
    for each (let category in ChromelessPolicy.xpcom_categories) {
        categoryManager.addCategoryEntry(category, ChromelessPolicy.classDescription, ChromelessPolicy.contractID, false, true);
    }
    

    Pull Request on github for those that are interested: https://github.com/mozilla/chromeless/pull/114

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I need to clean up various Word 'smart' characters in user input, including but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.