# How to add header and body to empty tab?

**URL:** https://discourse.mozilla.org/t/how-to-add-header-and-body-to-empty-tab/10121
**Category:** Development
**Created:** [August 5, 2016, 9:31am UTC](https://discourse.mozilla.org/t/how-to-add-header-and-body-to-empty-tab/10121 "2016-08-05T09:31:04Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![h4ever](https://avatars.discourse-cdn.com/v4/letter/h/dc4da7/32.png) [@h4ever](https://discourse.mozilla.org/u/h4ever)
#### Post date: [August 5, 2016, 9:31am UTC](https://discourse.mozilla.org/t/how-to-add-header-and-body-to-empty-tab/10121/1 "2016-08-05T09:31:05Z")

</div>

I have some questions. I just created new tab using tabs.create (no url).

1. How to add header and document, body into the tab (empty webpage just created)?

2. how to add listener, should I insert script or inject script what is better? I mean. If I skip the url, then what to do next?

PS:  
If url argument in tabs.create options is optional, then why this should not have solution?

---

<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: [August 6, 2016, 6:59pm UTC](https://discourse.mozilla.org/t/how-to-add-header-and-body-to-empty-tab/10121/2 "2016-08-06T18:59:42Z")

</div>

By header do you mean an html element at top? I think to do this, you should injected a content script which will set the HTML.

---

<div class="post-metadata">

### Author: ![h4ever](https://avatars.discourse-cdn.com/v4/letter/h/dc4da7/32.png) [@h4ever](https://discourse.mozilla.org/u/h4ever)
#### Post date: [August 7, 2016, 7:25am UTC](https://discourse.mozilla.org/t/how-to-add-header-and-body-to-empty-tab/10121/3 "2016-08-07T07:25:41Z")

</div>

I think this is not possible to inject content script when you have no url assigned with the tab.

Hence it is non-sense to have optional argument url in the options. This one should be required.

---

<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: [August 7, 2016, 7:52am UTC](https://discourse.mozilla.org/t/how-to-add-header-and-body-to-empty-tab/10121/4 "2016-08-07T07:52:24Z")

</div>

I think all tabs have a URL. If you are not seeing one, it is probably `about:blank`

---

<div class="post-metadata">

### Author: ![h4ever](https://avatars.discourse-cdn.com/v4/letter/h/dc4da7/32.png) [@h4ever](https://discourse.mozilla.org/u/h4ever)
#### Post date: [August 7, 2016, 8:01am UTC](https://discourse.mozilla.org/t/how-to-add-header-and-body-to-empty-tab/10121/5 "2016-08-07T08:01:29Z")

</div>

I have written in the question that you create empty tab without url.

---

<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: [August 7, 2016, 8:18am UTC](https://discourse.mozilla.org/t/how-to-add-header-and-body-to-empty-tab/10121/6 "2016-08-07T08:18:59Z")

</div>

Yeah it’s a funky thing, blank in the URL bar means `about:blank` or `about:newtab`. To verify, after that blank tab opens, open borwser console, then type this code:

```
console.log(gBrowser.selectedBrowser.currentURI.spec)

```

Whatever URL that logs, you can inject a content script to that. It should tell you it is `about:blank`

---

<div class="post-metadata">

### Author: ![h4ever](https://avatars.discourse-cdn.com/v4/letter/h/dc4da7/32.png) [@h4ever](https://discourse.mozilla.org/u/h4ever)
#### Post date: [August 7, 2016, 9:26am UTC](https://discourse.mozilla.org/t/how-to-add-header-and-body-to-empty-tab/10121/7 "2016-08-07T09:26:01Z")

</div>

> [@noitidart](#):
>
> gBrowser

Sorry I dont know what is gBrowser. I am [reading](https://developer.mozilla.org/en-US/Add-ons/Code_snippets/Tabbed_browser) some information about it to understand it more.  
E.g. “gBrowser is only accessible from the scope of the browser window (browser.xul)” But I do not know what is the xul.

“You can access gBrowser only after the browser window is fully loaded. If you need to do something with gBrowser right after the window is opened, listen for the load event and use gBrowser in the event listener.”  
When the header and scripts are not loaded, how can you add a listener?

Did you mean I to do something like this?

```
"content_scripts": [
    {
    "matches": ["about:config"],
    "js": [
      "test.js"
      ]
    }
  ],

```

This will not work because matching rules are not allowing this.

---

<div class="post-metadata">

### Author: ![freaktechnik](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/freaktechnik/32/37766_2.png) [@freaktechnik](https://discourse.mozilla.org/u/freaktechnik)
#### Post date: [August 7, 2016, 11:33am UTC](https://discourse.mozilla.org/t/how-to-add-header-and-body-to-empty-tab/10121/8 "2016-08-07T11:33:06Z")

</div>

Yes, you are correct in your assumption that you cannot attach to about:blank. Instead you should load your own page in a tab (which could already have the content you need).

---

<div class="post-metadata">

### Author: ![h4ever](https://avatars.discourse-cdn.com/v4/letter/h/dc4da7/32.png) [@h4ever](https://discourse.mozilla.org/u/h4ever)
#### Post date: [August 7, 2016, 1:52pm UTC](https://discourse.mozilla.org/t/how-to-add-header-and-body-to-empty-tab/10121/9 "2016-08-07T13:52:52Z")

</div>

Thanks, I have did it yesterday so this is solved.
