Reputation: 151712
I've written a Chrome extension that replaces the new tab if the user wants that. It works by intercepting tabs.onUpdated and redirecting chrome://newtab/
to another page from the extension, as described in this answer.
The problem is that the address bar of that page keeps the (ugly) URL of the HTML within the extension, e.g. chrome-extension://hibkhcnpkakjniplpfblaoikiggkopka/html/newtabl.html
. How can that URL be replaced with the empty string?
I've tried history.replaceState, but the best that can do is to change the file (newtab.html
) in the path. Using an http:// URL crashes the extension:
history.replaceState({}, 'iDoRecall practice', 'http://type-anything-here.com');
Any clever way to clear the Omnibox?
Upvotes: 0
Views: 338
Reputation: 73716
Put simply, History API can only change the path part of the URL, not the origin (protocol://host:port) for an obvious reason of preventing site fraud:
If the origin of the resulting absolute URL is not the same as the origin of the responsible document specified by the entry settings object, and either the path or query components of the two parsed URLs compared in the previous step differ, throw a SecurityError exception and abort these steps. (This prevents sandboxed content from spoofing other pages on the same origin.)
The omnibox may be empty only in one case: on a new tab page, that is you'll have to replace the new tab in manifest.json in chrome_url_overrides.
Upvotes: 1