# Set Browser Home Page using Add-on

**URL:** <https://discourse.mozilla.org/t/set-browser-home-page-using-add-on/4161>\
**Category:** Add-ons\
**Created:** [September 21, 2015, 11:17am UTC](https://discourse.mozilla.org/t/set-browser-home-page-using-add-on/4161 "2015-09-21T11:17:29Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ashish](https://avatars.discourse-cdn.com/v4/letter/a/ea666f/32.png) [@Ashish](https://discourse.mozilla.org/u/Ashish)\
**Post date:** [September 21, 2015, 11:17am UTC](https://discourse.mozilla.org/t/set-browser-home-page-using-add-on/4161/1 "2015-09-21T11:17:30Z")

</div>

Hi All,

I am creating Firefox Add-on with help of below Url.  
[https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials](https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials)

I have successfully created Firefox add-on.

Now I want to achieve following functionality like,

1. Setting Home Page of Browser using Add-on.
2. Where can I find all the addon event(Install/Uninstall/Load) of Add-on?  
(I want to integrate Google analytic)

Could you please help me with my functionality?

Regards  
Ashish Sapkale

---

<div class="post-metadata">

**Author:** ![noitidart](https://avatars.discourse-cdn.com/v4/letter/n/9f8e36/32.png) [@noitidart](https://discourse.mozilla.org/u/noitidart)\
**Post date:** [September 21, 2015, 11:31am UTC](https://discourse.mozilla.org/t/set-browser-home-page-using-add-on/4161/2 "2015-09-21T11:31:27Z")

</div>

Firefox removed the pref that allowed easy overriding of the new tab page.

I thought I could use http-on-modify-request to listen for about:newtab but apparently going to about:newtab loads `https://tiles.services.mozilla.com/v3/links/view` so i tried to listen for that and do `redirectTo` but its not working its so weird. Anyone know why? Here’s my code:

```
var { interfaces: Ci, utils: Cu, classes: Cc, results: Cr } = Components;
Cu.import('resource://gre/modules/Services.jsm');
Cu.import('resource://gre/modules/devtools/Console.jsm');

var observers = {
    'http-on-modify-request': {
        observe: function (aSubject, aTopic, aData) {
            console.info('http-on-modify-request: aSubject = ' + aSubject + ' | aTopic = ' + aTopic + ' | aData = ' + aData);
            var httpChannel = aSubject.QueryInterface(Ci.nsIHttpChannel);
                    var requestUrl = httpChannel.URI.spec
                    console.error('requestUrl:', requestUrl);
                    if (requestUrl == 'https://tiles.services.mozilla.com/v3/links/view') {
                        console.error('yes redir now!!');
                        // httpChannel.cancel(Cr.NS_BINDING_ABORTED);
                        httpChannel.redirectTo(Services.io.newURI('data:text/html,you went to about:newtab page and i replaced it with this', null, null));
                    }
        },
        reg: function () {
            Services.obs.addObserver(observers['http-on-modify-request'], 'http-on-modify-request', false);
        },
        unreg: function () {
            Services.obs.removeObserver(observers['http-on-modify-request'], 'http-on-modify-request');
        }
    }
};

//register all observers
for (var o in observers) {
    observers[o].reg();
}
```

---

<div class="post-metadata">

**Author:** ![MartijnJ](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/martijnj/32/2849_2.png) [@MartijnJ](https://discourse.mozilla.org/u/MartijnJ)\
**Post date:** [September 21, 2015, 12:31pm UTC](https://discourse.mozilla.org/t/set-browser-home-page-using-add-on/4161/3 "2015-09-21T12:31:38Z")

</div>

You can change the home page by changing the `browser.startup.homepage` preference.

Which you can do with the preferences/service module:  
[https://developer.mozilla.org/en-US/Add-ons/SDK/Low-Level\_APIs/preferences\_service](https://developer.mozilla.org/en-US/Add-ons/SDK/Low-Level_APIs/preferences_service)

Example:

```
require("sdk/preferences/service").set( "browser.startup.homepage", "MyCustomPage.com");

```

@noitidart You should checkout `resource:///modules/NewTabURL.jsm`

---

<div class="post-metadata">

**Author:** ![noitidart](https://avatars.discourse-cdn.com/v4/letter/n/9f8e36/32.png) [@noitidart](https://discourse.mozilla.org/u/noitidart)\
**Post date:** [September 21, 2015, 1:41pm UTC](https://discourse.mozilla.org/t/set-browser-home-page-using-add-on/4161/4 "2015-09-21T13:41:13Z")

</div>

O interesting, i thought they removed that pref. Or there were plans to no?

---

<div class="post-metadata">

**Author:** ![MartijnJ](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/martijnj/32/2849_2.png) [@MartijnJ](https://discourse.mozilla.org/u/MartijnJ)\
**Post date:** [September 21, 2015, 3:05pm UTC](https://discourse.mozilla.org/t/set-browser-home-page-using-add-on/4161/5 "2015-09-21T15:05:59Z")

</div>

I think you are confusing the home page and newtab page with each other.

The newtab page pref(`browser.newtab.url`) has been removed, not the home page pref.

Here is the bug for it:  
[https://bugzilla.mozilla.org/show\_bug.cgi?id=1118285](https://bugzilla.mozilla.org/show_bug.cgi?id=1118285)

---

<div class="post-metadata">

**Author:** ![noitidart](https://avatars.discourse-cdn.com/v4/letter/n/9f8e36/32.png) [@noitidart](https://discourse.mozilla.org/u/noitidart)\
**Post date:** [September 22, 2015, 6:15am UTC](https://discourse.mozilla.org/t/set-browser-home-page-using-add-on/4161/6 "2015-09-22T06:15:18Z")

</div>

Ooo that’s it! 😄  
Thanks man, I’ll post another topic on how to override that new tab page (with my attempted code) as I’ll be needing it soon. 🙂

---

<div class="post-metadata">

**Author:** ![Ashish](https://avatars.discourse-cdn.com/v4/letter/a/ea666f/32.png) [@Ashish](https://discourse.mozilla.org/u/Ashish)\
**Post date:** [September 22, 2015, 9:32am UTC](https://discourse.mozilla.org/t/set-browser-home-page-using-add-on/4161/7 "2015-09-22T09:32:23Z")

</div>

Thanks MartijnJ.

I have also set “require(“sdk/preferences/service”).set( “browser.newtab.url”, “[http://MyCustomPage.com](http://MyCustomPage.com)”);”

To set it on everypage(Tab)

---

<div class="post-metadata">

**Author:** ![Ashish](https://avatars.discourse-cdn.com/v4/letter/a/ea666f/32.png) [@Ashish](https://discourse.mozilla.org/u/Ashish)\
**Post date:** [September 22, 2015, 10:08am UTC](https://discourse.mozilla.org/t/set-browser-home-page-using-add-on/4161/8 "2015-09-22T10:08:27Z")

</div>

> [@Ashish](#):
>
> Where can I find all the addon event(Install/Uninstall/Load) of Add-on?

If possible Could you help me with my 2nd query?

---

<div class="post-metadata">

**Author:** ![MartijnJ](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/martijnj/32/2849_2.png) [@MartijnJ](https://discourse.mozilla.org/u/MartijnJ)\
**Post date:** [September 22, 2015, 11:34am UTC](https://discourse.mozilla.org/t/set-browser-home-page-using-add-on/4161/9 "2015-09-22T11:34:58Z")

</div>

I think this is what you are looking for:  
[https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Listening\_for\_load\_and\_unload](https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Listening_for_load_and_unload)

---

<div class="post-metadata">

**Author:** ![Ashish](https://avatars.discourse-cdn.com/v4/letter/a/ea666f/32.png) [@Ashish](https://discourse.mozilla.org/u/Ashish)\
**Post date:** [September 22, 2015, 11:49am UTC](https://discourse.mozilla.org/t/set-browser-home-page-using-add-on/4161/10 "2015-09-22T11:49:11Z")

</div>

Thanks a Lot MartijnJ!

Very quick reply…

Yes, This is what I am looking for. 😄
