Content script triggered for omnibox

85 views
Skip to first unread message

Bubba Bubbs

unread,
Mar 28, 2012, 12:21:54 PM3/28/12
to Chromium-extensions
/*** I've asked this question on StackOveflow, but the only answer
I've gotten so far isn't very helpful. I am re-posting here, as it
seems like this board is still pretty active ***/

My Chrome extension injects a content script into every page
("matches": ["http:///", "https:///"]). The content script will fire a
message (chrome.extension.sendRequest) to the background page, and the
background page registers an event handler:

chrome.extension.onRequest.addListener( function (request, sender,
callback) {…} );

I have noticed that those events are fired as I start typing in the
omnibox – even before I hit Enter to load the destination page.

Scenario: - Launch Chrome - Start typing in the omnibox. In fact, as
soon as the omnibox has focus, my
chrome.extension.onRequest.addListener() event handler
[background.html] is fired.

The weird thing is that the sender.tab.index value is -1, so it
doesn’t map to a “real” tab. Also, as I continue switching focus away
from, and back to the omnibox, the events keep firing. Each time,
sender.tab.index is -1, but sender.tab.id is being incremented by 2
(43, 45, 47, …). This behavior is easily reproducible.

Then, when I actually choose a URL (say, xyz.com) by hitting Enter in
the omnibox, and the page loads in the browser/tab, I get yet another
event. This time, however, sender.tab.index is non-negative – it
represents the actual browser tab, and my content script handler can
do its work.

Is this behavior – content script being injected into a “phantom” page
for omnibox actions – known, and is it documented anywhere? And what
is the proper way for my event handler to handle this? Let’s say my
content script handler needs to manipulate the web page. Should I be
checking sender.tab.index, and only doing the work if
sender.tab.index != -1?

Thanks!

Bubba Bubbs

unread,
Mar 28, 2012, 12:26:39 PM3/28/12
to Chromium-extensions
Typo, sorry. My "matches" is actually:
"matches": [ "http://*/*", "https://*/*" ]

Devin

unread,
Mar 29, 2012, 11:44:22 AM3/29/12
to Chromium-extensions
wow, sounds like some complex things are going on. In my extension I
modify Google search, and can tell you that when you use the instant
search from the omnibar, there is a 'phantom' page that is loading
when your doing this, and the url for it is https://www.google.com/
webhp?sourceid=chrome-instant&ie=UTF-8&ion=1

then when you accept a result and hit enter, this page url is like:

https://www.google.com/webhp?sourceid=chrome-instant&ie=UTF-8&ion=1#MOAR&PARAMS

thats all I know, please update on what you learn!

PhistucK

unread,
May 10, 2012, 2:24:53 AM5/10/12
to Bubba Bubbs, Chromium-extensions
That 'hidden' tab that sends that request is probably a prerendered page.

PhistucK




--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.


Devin

unread,
May 10, 2012, 2:25:16 PM5/10/12
to Chromium-extensions
Indeed, you can also send document.webkitVisibilityState and see if it
indicates "visible", "hidden", or "prerender"


On May 9, 11:24 pm, PhistucK <phist...@gmail.com> wrote:
> That 'hidden' tab that sends that request is probably a prerendered page.
>
> ☆*PhistucK*
> > To post to this group, send email to chromium-extensi...@chromium.org.
> > To unsubscribe from this group, send email to
> > chromium-extensions+unsubscr...@chromium.org.

Bubba Bubbs

unread,
May 16, 2012, 8:33:36 PM5/16/12
to Chromium-extensions
PhistucK: Is there any documentation how page prerendering works? How
Chrome pre-loads/pre-renders/caches pages?

A related issue: My content scripts are not being injected into such
cached/pre-rendered pages. Here’s a scenario:

1. Go to xyz.com; the page is loaded for the first time.
2. Go to someOther.com.
3. Go to xyz.com again. As I’m typing “xyz.com” in the omnibox, Chrome
is prerendering the page. I know that because my
chrome.webNavigation.onCompleted is triggered. However, I don’t think
my content script is injected, because…
4. … I hit Enter, the (preloaded) xyz.com page now appears in the
active tab, but my injection script doesn’t seem to be running.

Also is there an event in step [3.] that I can listen to? I am
getting neither chrome.webNavigation.onCompleted nor
chrome.tabs.onUpdated.

Thanks


On May 10, 12:24 am, PhistucK <phist...@gmail.com> wrote:
> That 'hidden' tab that sends that request is probably a prerendered page.
>
> ☆*PhistucK*
> > To post to this group, send email to chromium-extensi...@chromium.org.
> > To unsubscribe from this group, send email to
> > chromium-extensions+unsubscr...@chromium.org.

Bubba Bubbs

unread,
May 17, 2012, 11:48:56 AM5/17/12
to Chromium-extensions
I meant:

is there an event in step [__4__] that I can listen to?  I am getting
neither chrome.webNavigation.onCompleted nor chrome.tabs.onUpdated.
Reply all
Reply to author
Forward
0 new messages