# Create a new TAB and inject script

**URL:** https://discourse.mozilla.org/t/create-a-new-tab-and-inject-script/9526
**Category:** Development
**Created:** [July 2, 2016, 9:53pm UTC](https://discourse.mozilla.org/t/create-a-new-tab-and-inject-script/9526 "2016-07-02T21:53:57Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![yod](https://avatars.discourse-cdn.com/v4/letter/y/c5a1d2/32.png) [@yod](https://discourse.mozilla.org/u/yod)
#### Post date: [July 2, 2016, 9:53pm UTC](https://discourse.mozilla.org/t/create-a-new-tab-and-inject-script/9526/1 "2016-07-02T21:53:57Z")

</div>

Hi, I have tried everything but i can’t do it.

I keep getting the errors:  
Could not establish connection. Receiving end does not exist.  
No matching window

I create a new tab this way:  
**browser.tabs.create({ url: “[http://www.mysite.com/page.php](http://www.mysite.com/page.php)”, active: true }, f);**

then through  
**browser.tabs.onUpdated.addListener(myfunc)**  
I check the tabId and his status to be “complete” before injecting my content script with:  
**browser.tabs.executeScript(tabId, {file: “/content\_scripts/myscript.js”});** (I also tried to use **runAt: “document\_start”** in the extensionTypes.InjectDetails)  
**chrome.tabs.sendMessage(tabId, null);**

If I open the tab manually without using browser.tabs.create everything works fine.

---

<div class="post-metadata">

### Author: ![jorgev](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jorgev](https://discourse.mozilla.org/u/jorgev)
#### Post date: [July 5, 2016, 4:32pm UTC](https://discourse.mozilla.org/t/create-a-new-tab-and-inject-script/9526/2 "2016-07-05T16:32:34Z")

</div>

Can you show all of the code? Are you adding the event listener _after_ you create the tab?

---

<div class="post-metadata">

### Author: ![yod](https://avatars.discourse-cdn.com/v4/letter/y/c5a1d2/32.png) [@yod](https://discourse.mozilla.org/u/yod)
#### Post date: [July 5, 2016, 5:03pm UTC](https://discourse.mozilla.org/t/create-a-new-tab-and-inject-script/9526/3 "2016-07-05T17:03:33Z")

</div>

Thank you for your answer. At the end I gave up and used the old sdk and everything went fine.  
Anyway I added the event listener before opening the new tab, I could see when the tab was “loading” and when it was “completed”, maybe Im wrong but it looks like a bug

---

<div class="post-metadata">

### Author: ![jorgev](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jorgev](https://discourse.mozilla.org/u/jorgev)
#### Post date: [July 12, 2016, 4:00pm UTC](https://discourse.mozilla.org/t/create-a-new-tab-and-inject-script/9526/4 "2016-07-12T16:00:24Z")

</div>

It’d be great if you can create a minimal test case and [submit a bug report here](https://bugzilla.mozilla.org/enter_bug.cgi?product=Toolkit&component=WebExtensions). Thanks!
