I think this method is better than the @Chris method.
document.location.href = url;
Update: I tested it and succeeded on my chrome. Although this method is slow, too. But this is faster than the @Chris method.
This is manifest.json
{ "name" : "my extension", "description" : "my extension", "version" : "0.1", "manifest_version" : 2, "chrome_url_overrides" : { "newtab" : "html/index.html#newTab" }, "permissions" : [ "tabs", "<all_urls>", "history", "bookmarks", "chrome://favicon/*", "unlimitedStorage", "management", "clipboardWrite", "clipboardRead", "contextMenus", "notifications", "storage" ], "browser_action" : { "default_icon" : "icon.png", "default_popup" : "html/popup.html", "default_title": "Click here!" }, "options_page": "html/options.html" }
This is index.html
<!DOCTYPE html> <html> <head> <script type="text/javascript" src="/js/newTabCheck.js"></script> <title></title> </head> <body></body> </html>
This is newTabCheck.js
if (window.location.hash == '#newTab') { window.document.title = 'Loading...'; chrome.storage.sync.get({ file_url : 'http://www.google.com' }, function (items) { document.location.href = items.file_url; }); }
This is options.html
<html> <head> <title>My Test Extension Options</title> </head> <body>file path: <form> <input type="text" id="file_url" /> <br /> <button id="save">save</button> <label id="status"></label> <script type="text/javascript" src="/js/options.js"></script></form> </body> </html>
This is options.js
// Saves options to chrome.storage function save_options() { var file_url = document.getElementById("file_url").value; chrome.storage.sync.set({ file_url : file_url }, function () { // Update status to let user know options were saved. var status = document.getElementById('status'); status.textContent = 'save success!'; setTimeout(function () { status.textContent = ''; }, 750); }); } // Restores select box and checkbox state using the preferences // stored in chrome.storage. function restore_options() { chrome.storage.sync.get({ file_url : 'http://www.google.com' }, function (items) { document.getElementById("file_url").value = items.file_url; }); } document.addEventListener('DOMContentLoaded', restore_options); document.getElementById('save').addEventListener('click', save_options);
Just set file_url as focus.html
<html> <head><title></title></head> <body> save path: <input type="text" id="file_url"></input> <script type="text/javascript"> document.getElementById('file_url').focus(); </script> </body> </html>
What all.
The reason for writing this extension is the Vimium extension. Then, when I type "t" to open newtab, I can use vimiun without a mouse. For this reason you do not need to write javascript code document.getElementById('file_url').focus(); .