I'm trying to create an extension for Google Chrome overriding the "new tab" page, in which there is content in JavaScript. In the first tab, it runs correctly, but when new tabs are opened, the scripts don't work. What should I do for fixing it?
-
without any code, we can't help you. Why do you need to override the new tab button?– SenjaiMay 12, 2013 at 2:02
2 Answers
You can make an extension for Google Chrome. Chrome extensions require a manifest.json
file to be included, and you can set overridable pages to bookmarks
history
or newtab
. Like such:
"chrome_url_overrides" : {
"newtab": "index.html"
},
For more info about making Chrome extensions, read the docs.
I'm not sure what you mean by 'content in JavaScript'.
You can check out the code for my chrome extension, New Tab Redirect: https://github.com/jimschubert/newtab-redirect
The way I have it set up is that there is a redirect.html
page which is used as the override page. On load, it checks for a user-specified url from the background/event page (background.js), then redirects to that url with a simple JavaScript redirect.
The master
branch is v1.0 (background page) and the 2.0 branch uses an event page.
edit To specifically answer why you might be having problems with your code, without seeing any actual code.. I assume you're doing the initialization of your script in a background page in very much the same way as in my extension and querying that data from the redirect page, where you're then getting/setting data in local storage.
If any of that data needs to change, you can't use local storage from your redirecting page. Instead, you need to send the data back to the background page and store options there. Think of your background page as a service and your redirecting page as a very thin, very stateless client.