Closing new tab on Google Chrome Extension

This is something very new which i recently having problem with. I would like to open a new website and check for a certain criteria in my google chrome extension and close that particular new tab that i just open using chrome.tabs.create. However, the following code doesn't work when i inject the code into the new tab


The condition of closing a new tab has been fulfilled however i am not able to close that tab. Google for a few times doesn't give me any answer to my question until i try something new and it works. Looking at the below code,

chrome.tabs.create({'url': tab.url + 'feed/'}, 
function(tab) {
	chrome.tabs.executeScript(, {code: "this.close();"});

take note that i uses chrome.tabs.create to open up a new tab on my google chrome extension. After i validate my url i injected a close command using "this" instead of "windows" with the id of the tab i just open. Apparently, it works!

Hope it helps someone 🙂

Sending data from background.html to popup display in Google Chrome Extension

You are trying to send data from your background.html back to your popup display in your google chrome extension. However, all you read was sending using message in google chrome to initial a one way message from your background.html to your content_script.js. But you do not understand why they are using a "tabs" api instead of extensions since you are still talking to your extension instead of the page itself.

Well, you are not wrong here to question the answer given from your result. The reason being is that you do not need to send data from background.html to your popup display. The reason is pretty simple, they are not separated. However, you do not know how to update the popup display when you get the data on your background.html. I believe the issue is similar to the one i previously written. You do not need that additional background.html if you are going to update your popup display and not working with other extension. All you have to do is write all your listener (assuming content_script is firing up to the extension) to your popup display. And you should get all you want in popup display without getting all headache about background.html not working etc. Hence,

  1. Copy all your background.html code into popup display
  2. Remove background.html entirely on manifest.json
  3. Now try to update like a normal page on your popup display
And it should do the trick. Hope it helps 🙂

How to get Popup and onClick work together on Google Chrome Extension

Firstly, if you try to use a popup in your manifest.json and find out that your chrome broweraction onclick listener doesn't seems to work. You are in the right place then. And if you read properly on Google Chrome Extension API page, the following onclick will not work properly with popup if you have define it on your manifest.json file.

chrome.browserAction.onClicked.addListener(function(Tab tab) {...});

Fired when a browser action icon is clicked. This event will not fire if the browser action has a popup.

Well, i have another solution for you if you want both popup and onclick on Google Chrome extension to work together.

Popup and onclick working together on Google Chrome extension

Here is probably what you are doing. You are most likely placing your onclick event handler on your background.html file and awaiting for click of your chrome extension to do something within the onclick. And maybe sending them to your popup display. You soon realize that if the popup options is set on your manifest, your onclick won't work. Now, in order to make everything work, just use the popup instead of both as popup will overwrite the onclick event handler and you want the display to be out. What you should do is to paste the code from your background.html to your popup as you shouldn't have the need for a background.html as you are not communicating with many extension. Therefore, you should really either use popup or an onclick but not both 🙂

You might have guess, i was the dumb one here who did the above and realize i'm dumb. *shy* . hahaha. Hope it helps 🙂