How to add header and body to empty tab?

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?

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.

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.

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

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

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

Sorry I dont know what is gBrowser. I am reading 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.

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).

1 Like

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