Google Chrome Extension default in a new tab - google-chrome-extension

so I am trying to make a google chrome extension and I want it to open when you open a new tab. Kind of like muz.li. Basically, when you press ctrl+t to open a new tab instead of showing google, it shows my extension.
Thanks!

Simple add the code below to open the extension when a new tab is opened, you don't need a background js or html file. It is in the manifest.json file:
"chrome_url_overrides": {
"newtab": "page.html"
},

I suggest to use the chrome.tabs.onCreated event to detect when someone opens up a new tab.
https://developer.chrome.com/extensions/tabs#event-onCreated

Related

Chrome background.js do not run unless manually click refresh icon in extension page every time the chrome first open

Recently I am developing an extension which listens to tab change and do some stuff according to it. Now I wrote my main logic in chrome.runtime.onInstalled.addListener in background.js. I used unpacked version for development. However, to make the extension work, I need to manually go to the extension page and click refresh icon every time when first open a chrome window, otherwise, it will not work. Is there a way to make the background.js run the code without manually click refresh button? I tried onStartup but it doesn't work out.
Although not ideal, you can make the background script run persistently if you modify your manifest.json to...
{
"name": "My extension",
...
"background": {
"scripts": ["background.js"],
"persistent": true
},
...
}
This is not recommended because background scripts can use a lot of resources so you should use something like chromes messaging API to run only on set/specific events.
If you need to look into changing your background script, look at this for more information.

gulp refresh active tab after code change in chrome extension

I'm developing a chrome extension and I want to automatically refresh the active tab after a code change
I got gulp-open to work so I don't need to navigate to chrome://extensions anymore and manually click "reload"
now only the active tab refresh remains
I've tried gulp-livereload but couldn't get it to work for developing a chrome extension
any ideas how to approach this?
Could you post the code of your chrome extension? Without much info, I hope this is helpful. You can inject the code below to refresh the page after the chrome extension is reloaded:
chrome.tabs.query({
active: true, // Select active tabs
lastFocusedWindow: true // In the current window
}, function(tabs) {
// Since there can only be one active tab in one active window,
// the array has only one element
var tab = tabs[0];
// Javascript to reload the page
var code = 'window.location.reload();';
// Execute the code for the current tab
chrome.tabs.executeScript(tab.id, {code: code});
});

Opening chrome extension in new tab

Is this still valid?
"app": {
"launch": {
"local_path": "window.html",
"container": "tab"
}
},
I'm using Chrome v46 and it works but I'd like to be sure it is not a bug.
I cannot see anything like this in the manifest file reference
Your manifest snippet (containing app.launch.local_path) describes a legacy packaged app. These are deprecated and not officially supported any more.
If you want to have an icon in the app launcher, then you need to create a Chrome app (if you want to host the content in the package) or a hosted app (if you want to host the content online).
If you don't want to create an app, but an extension, then you could use a browser action button to add a button to the toolbar, and then open a page in a new tab using chrome.tabs.create. Or, if your actual goal is replacing the new tab page, use chrome_url_overrides to override newtab.

Chrome extension : how to detect click in background process?

I am devlopping a google chrome extension
I have a background process and a popup window.
I want to not use the popup window any more, but instead open a web browser window when chrome extension button is clicked:
How do I do that : How do I detect the click inside background.js ?
This is quite easy
chrome.browserAction.onClicked.addListener(function(tab) {
// The action icon has been clicked
});
You'll have to declare the extension as a browser action in your manifest and remove the popup option

Create new tab with developer tools open

I have a working Chrome Extension that opens a new tab and navigates to the specified URL. I'm looking to see if I can somehow have that new tab be opened with developer tools open as well. Is this possible?
chrome.tabs.create({
active: true,
url: "http://www.google.com"
}, createTabListener);
Unfortunately, it is not possible at the moment. You can vote for this issue to support the feature request: https://code.google.com/p/chromium/issues/detail?id=410958

Resources