I'm looking for advice on how to receiving messages from the
background page prior to the page rendering. I've looked at ports and
sendRequest, but both come well after the page renders; is there a
different approach I should try? Here's some background on what I'm
trying to do:

The extension I'm writing remembers your zoom setting across page
loads. The zoom setting is persisted per-domain in the localStorage of
the extension's background page. This means every time a new page is
loaded, my content script must open a communication channel with the
background page and retrieve the saved zoom setting. The response from
the background page needs to be received prior to the page rendering,
or there will be a nasty flicker as I zoom the page after it's already
visible.

Below is a representative benchmark of the latencies from a content
script to a background page while loading a simple page like
http://news.ycombinator.com/item?id=964518. The number to the left of
each message is milliseconds after page load.

1 beginning to execute myContentScript.js
4 making request to background page using "sendRequest"
6 making request to background page using "postMessage"
77 response from "sendRequest" was received
83 Response from background page using ports, connection open
91 Response from background page using ports, message received
846 onDomready

Two things to note:
 * the 77ms response comes after the page has already rendered (go
Chrome)
 * The response times are highly variable; on some page loads,
messages from the background page can take up to 250ms.

The need for the early communication channel to the background page is
driven by my use of the background page's localStorage. I supposed I
could also store the zoom setting in the content script's
localStorage, but then I would not have this data centralized in any
way and so it would be hard to remove down the road. Is it bad form to
store data in a content script's localStorage?

-Phil Crosby

--

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


Reply via email to