{"action":"created","issue":{"url":"https://api.github.com/repos/EFForg/privacybadger/issues/1865","repository_url":"https://api.github.com/repos/EFForg/privacybadger","labels_url":"https://api.github.com/repos/EFForg/privacybadger/issues/1865/labels{/name}","comments_url":"https://api.github.com/repos/EFForg/privacybadger/issues/1865/comments","events_url":"https://api.github.com/repos/EFForg/privacybadger/issues/1865/events","html_url":"https://github.com/EFForg/privacybadger/issues/1865","id":296543305,"number":1865,"title":"Update conditional content script injection to use faster methods","user":{"login":"alexristich","id":11308076,"avatar_url":"https://avatars1.githubusercontent.com/u/11308076?v=4","gravatar_id":"","url":"https://api.github.com/users/alexristich","html_url":"https://github.com/alexristich","followers_url":"https://api.github.com/users/alexristich/followers","following_url":"https://api.github.com/users/alexristich/following{/other_user}","gists_url":"https://api.github.com/users/alexristich/gists{/gist_id}","starred_url":"https://api.github.com/users/alexristich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexristich/subscriptions","organizations_url":"https://api.github.com/users/alexristich/orgs","repos_url":"https://api.github.com/users/alexristich/repos","events_url":"https://api.github.com/users/alexristich/events{/privacy}","received_events_url":"https://api.github.com/users/alexristich/received_events","type":"User","site_admin":false},"labels":[{"id":570309696,"url":"https://api.github.com/repos/EFForg/privacybadger/labels/performance","name":"performance","color":"88166d","default":false}],"state":"open","locked":false,"assignee":{"login":"alexristich","id":11308076,"avatar_url":"https://avatars1.githubusercontent.com/u/11308076?v=4","gravatar_id":"","url":"https://api.github.com/users/alexristich","html_url":"https://github.com/alexristich","followers_url":"https://api.github.com/users/alexristich/followers","following_url":"https://api.github.com/users/alexristich/following{/other_user}","gists_url":"https://api.github.com/users/alexristich/gists{/gist_id}","starred_url":"https://api.github.com/users/alexristich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexristich/subscriptions","organizations_url":"https://api.github.com/users/alexristich/orgs","repos_url":"https://api.github.com/users/alexristich/repos","events_url":"https://api.github.com/users/alexristich/events{/privacy}","received_events_url":"https://api.github.com/users/alexristich/received_events","type":"User","site_admin":false},"assignees":[{"login":"alexristich","id":11308076,"avatar_url":"https://avatars1.githubusercontent.com/u/11308076?v=4","gravatar_id":"","url":"https://api.github.com/users/alexristich","html_url":"https://github.com/alexristich","followers_url":"https://api.github.com/users/alexristich/followers","following_url":"https://api.github.com/users/alexristich/following{/other_user}","gists_url":"https://api.github.com/users/alexristich/gists{/gist_id}","starred_url":"https://api.github.com/users/alexristich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexristich/subscriptions","organizations_url":"https://api.github.com/users/alexristich/orgs","repos_url":"https://api.github.com/users/alexristich/repos","events_url":"https://api.github.com/users/alexristich/events{/privacy}","received_events_url":"https://api.github.com/users/alexristich/received_events","type":"User","site_admin":false}],"milestone":null,"comments":4,"created_at":"2018-02-12T22:13:11Z","updated_at":"2018-03-29T05:33:44Z","closed_at":null,"author_association":"COLLABORATOR","body":"Currently we inject content scripts conditionally with message passing, where the content script will query the background page as to whether it should inject itself into the page. This has the potential for the content script to be injected after a page script has already executed. In the case of fingerprinting.js, this means we may not catch an instance of fingerprinting because the fingerprinting occurred before our content script was run.\r\n\r\nMozilla has released a new API (https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/contentScripts/register) which looks promising. It currently only works for Firefox 59+.\r\n\r\nAnother alternative is `tabs.executeScript()` (https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/tabs/executeScript), which may provide faster injection of content scripts than our current message passing approach.\r\n\r\nA final(?) contender is `webNavigation.onCommitted` (https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/webNavigation/onCommitted), which, according to Adguard is the fastest means of conditionally injecting a content script: https://github.com/gorhill/uBlock/issues/1930#issuecomment-294486152"},"comment":{"url":"https://api.github.com/repos/EFForg/privacybadger/issues/comments/377126782","html_url":"https://github.com/EFForg/privacybadger/issues/1865#issuecomment-377126782","issue_url":"https://api.github.com/repos/EFForg/privacybadger/issues/1865","id":377126782,"user":{"login":"alexristich","id":11308076,"avatar_url":"https://avatars1.githubusercontent.com/u/11308076?v=4","gravatar_id":"","url":"https://api.github.com/users/alexristich","html_url":"https://github.com/alexristich","followers_url":"https://api.github.com/users/alexristich/followers","following_url":"https://api.github.com/users/alexristich/following{/other_user}","gists_url":"https://api.github.com/users/alexristich/gists{/gist_id}","starred_url":"https://api.github.com/users/alexristich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexristich/subscriptions","organizations_url":"https://api.github.com/users/alexristich/orgs","repos_url":"https://api.github.com/users/alexristich/repos","events_url":"https://api.github.com/users/alexristich/events{/privacy}","received_events_url":"https://api.github.com/users/alexristich/received_events","type":"User","site_admin":false},"created_at":"2018-03-29T05:33:44Z","updated_at":"2018-03-29T05:33:44Z","author_association":"COLLABORATOR","body":"Following up on this issue, the current issue presented here is the \"slow\" conditional injection of content scripts. The reason for this \"slowness\" is that the content scripts need to know whether they should inject themselves into the page. A case where a content script should not inject itself is when the current site is whitelisted by the user.\r\n\r\nThe way this is currently achieved is using synchronous message passing with `chrome.runtime.sendMessage`. The proposed solutions above aim to address this, though the optimal solution is to use the new `browser.contentScripts` API. However, this API is currently only supported in Firefox 59+.\r\n\r\nIn order to fully leverage this new API, we must either (a) adjust how all current content scripts are declared and injected to avoid duplicate injection, or (b) duplicate all the current scripts, making necessary tweaks to support both methods and avoiding duplicate injection.\r\n\r\nBoth of these approaches have downsides, though given the limitations presented to content scripts and the requirements of our content scripts (i.e. injected as close to `document_start` as possible), there doesn't appear to be much room if any for flexibility outside these two options."}}
{"actor":{"display_login":"alexristich"}}