How do I programatically select the URL text once the new tab has loaded?
This is the code for redirect.js
/*global chrome,document,window */
(function init() {
"use strict";
chrome.storage.local.get(["url","tab.selected"], function (items) {
var url = items.url;
if(url) {
var selected = items["tab.selected"] === undefined ? true : (items["tab.selected"] == "true");
chrome.tabs.update({
"url": url,
"selected": selected
});
} else {
angular.resumeBootstrap();
}
});
}());
Soon as the page at "url" is loaded, I want it to automatically highlight the URL/omnibox text so the user can start typing without pressing Ctrl+A.
Thank you
EDIT: The focus is on the omnibox, but the text already present is not highlighted. I want it so that it is highlighted.
I was able to solve this using a Workaround.
Using Autohotkey, I coded a simple script which:
Simple. Elegant :P
Here is the code, modify as you wish (you will need Autohotkey_L to execute the code. Alternatively, you can turn it into an .exe for compatibility. See documentation on link above.
#Persistent
#SingleInstance, Force
#NoTrayIcon
SetBatchLines, -1
SetTitleMatchMode, 2
SetWinDelay, -1
/** Enter the name of the Chrome new tab page here, for me it is "Apps - Google Chrome" */
ChromeTab := "Apps - Google Chrome"
Gui +LastFound
hWnd := WinExist()
DllCall( "RegisterShellHookWindow", UInt,hWnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )
Return
ShellMessage( wParam,lParam ) {
Global Last
if (wParam = 16 && Last = 6) {
WinGetActiveTitle, T
if (T = ChromeTab) {
SendInput, {Control Down}l{Control Up}
}
}
Last := wParam
}