Skip to content

Investigate Faster Injection #184

@quoid

Description

@quoid

Related: #183 #178

At the time of posting this issue script injection occurs in the content script. The reason this is done is because reliably setting up injection through the background page, while theoretically should be faster, does not seem feasible.

The reason background injection does not seem feasible is that there seems to be no reliable method to detect when a user will visit a page. browser.webNavigation.onCommitted would seem like a good event listener to attach to but it's not. There's 2 reasons for this:

  1. The details object that is passed to the callback can not, currently, get the actual tabId where the navigation took place; the tabId is always 0.
  2. The event gets fired even if a user does not "commit" to the navigation. When a user starts entering an address in the the address bar of Safari and suggestions pre-fill the address bar, that triggers the event. There's no way to discern, through onCommitted, "real" navigation events and suggestions from the address bar. However, even one could make the distinction, the tabId would still be needed.

The other browser.webNavigation events either fire later than the content script or too early.

I looked into using the browser.tabs.onUpdated event and while this API works as it should, it does not seem viable. The injection time seems slower than content script injection and this event won't handle subframe injection. So additional programming would be required to also check if there are sub frames in the current tab. It's pointless if even without sub frame checking the injection time is slower.

Another method could be attaching to a browser.webRequest event except it seems like Safari does not currently support that API (even though MDN says it does) or there is a somewhat recent bug that is preventing access to that API. I am not sure if this API will be reliable and/or have the same issues as above, but it would worth investigating when whatever bugs, whether that is upstream or my implementation, are fixed.

For the time being I believe the extension is using the fastest possible injection method available. If anyone has opinions or suggestion please share.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Release

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions