On Aug 12, 2:29 pm, Yuzhu Shen <
yzs...@google.com> wrote:
> > 3. The requestID must remain constant across redirect loops
>
> > From the API spec, it sounds like this requestID will be constant even
> > across redirects, but its hard to tell for sure. I could easily see
> > certain redirect cases causing the implementation to forget to
> > preserve the requestID. This would be very bad.
>
> Would you please give me an example?
It could just be the Byzantine nature of the Firefox codebase, but the
channel behavior for different redirects sometimes behaves slightly
differently. I haven't dug far down deep enough to check exactly what
causes it, but I know some types of favicon redirects are one source
of trouble. It would be a good idea to make sure you have unit tests
or other testing code coverage for all the 30x codes going to and from
different schemes and origins.
> Yes, the requestId is supposed to be constant across redirects.
Ok, cool. It may be not a huge difficulty to do this in Chrome, but it
is something I'd keep an eye on in testing coverage or code review.
> > 4. onDOMContentLoaded may need multiple events (or maybe none)
>
> > One of the frustrating things about Firefox is being able to intercept
> > page load at points that make sense to an addon developer as opposed
> > to a browser implementer. In terms of the DOM, most addon developers
> > care about 3 points: the DOM is not yet built but you can now insert
> > your script and/or objects; the DOM is fully built but absolutely no
> > page scripts have run yet; and the DOM is built and all DOM loaded
> > events have been dispatched to page script. However, Firefox exposes
> > about a dozen different events here, none of which clearly map to this
> > simple model in terms of DOM events.
>
> It seems like you are talking about "run_at" property of "content_scripts"
> in manifest?
Yes. However that documentation is not 100% clear. I was planning on
writing a test extension to see if "document_start" would allow me to
wrap window.Date, window.screen, window.plugins and so on with my own
scripts, or if I would need to wait to "document_end". It's also not
100% clear if any page scripts would be able to run between
"document_start" and "document_end" to subvert my protections.
> > Maybe this is the wrong API set for any DOM-related events though, and
> > these types of events are only relevant to content scripts who
> > actually manipulate the DOM. Or maybe all three events should be
> > present in both places. Something to consider.
>
> I think onDOMContentLoaded is still meaningful. If you were building an
> extension that monitored performance, you'd be interested in knowing when
> the document finished loading and document+subresources finished loading.
Ok, sounds good. You might want to consider mirroring the content
script instrumentation points in that case. People may want
performance stats on those points as well, esp if they are wondering
about the performance impact of their content script addons.
> For many addons, it is very important to be able to tell if a request was due to navigation, or due to some automatic load condition.
>
> What do you mean by "automatic load condition"?
Browser updates, addon updates, other addon loads, search suggestions,
page javascript..
> > This is particularly problematic with async events though. If
> > onBeforeNavigate fires, but it is possible that an extension does so
> > much work there that it doesn't finish before onBeforeRequest is
> > delivered, this will cause unexpected behavior in addons that depend
> > on this knowledge.
>
> > If this cannot be avoided due to the event+process model, there should
> > be a flag added to the extraInfo object in onBeforeRequest to indicate
> > the request was generated due to a navigation. If this is already what
> > the "main_frame" request type is supposed to provide, then please
> > ignore this point entirely :)
>
> The "main_frame" ("sub_frame") request type, indicates the request will be
> used as page in a mainframe (subframe), which is resulted from a mainframe
> (subframe) navigation.
Ok. Sounds like this should be sufficient to not require subscription
to both onBeforeNavigate and onBeforeRequest.