sourcegraph/browser
Loïc Guychard 23652f4632
Bext: make permissions warning less scary (#10588)
Context: https://sourcegraph.slack.com/archives/CMT39K56Z/p1589217077358500

A user got concerned when seeing the "grant permissions" notification on a non-GitHub site, thinking that he needed to do it, and uninstalled the browser extension as a result.

This makes the warning more informative, explaining why this is necessary, and on which type of site.
2020-05-13 16:35:01 +02:00
..
.github mv client/browser browser (#3826) 2019-05-06 19:36:03 +02:00
config simplify shared Link component (#7205) 2019-12-14 21:40:02 -08:00
node_modules mv client/browser browser (#3826) 2019-05-06 19:36:03 +02:00
scripts Remove ./ (#10401) 2020-05-04 23:46:17 +02:00
src Bext: make permissions warning less scary (#10588) 2020-05-13 16:35:01 +02:00
.arcconfig mv client/browser browser (#3826) 2019-05-06 19:36:03 +02:00
.eslintignore Use TypeScript project references (#6053) 2019-11-12 12:26:21 +01:00
.eslintrc.js Use Mocha for e2e and regression tests (#7872) 2020-01-20 11:55:15 +01:00
.gitignore mv client/browser browser (#3826) 2019-05-06 19:36:03 +02:00
.stylelintrc.json Dont break GitHub file toolbar (#9517) 2020-04-02 23:19:01 +02:00
babel.config.js use base babel.config.js instead of duplicating Babel config (#3936) 2019-05-12 14:11:28 -07:00
cypress.json mv client/browser browser (#3826) 2019-05-06 19:36:03 +02:00
detailed_description.txt update browser extension description (#7120) 2019-12-08 13:41:09 -08:00
gulpfile.js Fix copying integration assets (#7195) 2019-12-14 19:54:21 -05:00
jest.config.js mv client/browser browser (#3826) 2019-05-06 19:36:03 +02:00
LICENSE mv client/browser browser (#3826) 2019-05-06 19:36:03 +02:00
package.json Remove TSLint (#9472) 2020-04-01 16:07:46 +02:00
postcss.config.js mv client/browser browser (#3826) 2019-05-06 19:36:03 +02:00
readme-load-extension-asset.png mv client/browser browser (#3826) 2019-05-06 19:36:03 +02:00
README.md Fix typos across sourcegraph repo (#8847) 2020-03-07 07:51:26 +02:00
tsconfig.json Add code intelligence and CI checks for GQL queries (#10352) 2020-05-05 15:17:12 +02:00
yarn.lock mv client/browser browser (#3826) 2019-05-06 19:36:03 +02:00

Sourcegraph browser extension

code style: prettier license

chrome version chrome users chrome rating\

Overview

The Sourcegraph browser extension adds tooltips to code on GitHub, Phabricator, and Bitbucket. The tooltips include features like:

  • symbol type information & documentation
  • go to definition & find references (currently for Go, Java, TypeScript, JavaScript, Python)
  • find references

🚀 Install: Sourcegraph for Chrome

🚀 Install: Sourcegraph for Firefox

It works as follows:

  • when visiting e.g. https://github.com/..., the extension injects a content script (inject.bundle.js)
  • there is a background script running to access certain chrome APIs, like storage (background.bundle.js)
  • a "code view" contains rendered (syntax highlighted) code (in an HTML table); the extension adds event listeners to the code view which control the tooltip
  • when the user mouses over a code table cell, the extension modifies the DOM node:
    • text nodes are wrapped in (so hover/click events have appropriate specificity)
    • element nodes may be recursively split into multiple element nodes (e.g. a &Router{namedRoutes: contains multiple code tokens, and event targets need more granular ranges)
    • We assume syntax highlighting takes care of the base case of wrapping a discrete language symbol
    • tooltip data is fetched from the Sourcegraph API
  • when an event occurs, we modify a central state store about what kind of tooltip to display
  • code subscribes to the central store updates, and creates/adds/removes/hides an absolutely positioned element (the tooltip)

Project layout

  • src/extension/
    • Entrypoint for browser extension builds. (Includes bundled assets, background scripts, options)
  • src/browser
  • src/libs/
    • Isolated pieces of the browser extension. This contains code that is specific to code hosts and separate "mini applications" included in the browser extension such as the src omnibar cli.
  • src/libs/phabricator/
  • src/shared/
    • Code shared by the extension and the libraries. Ideally, nothing in here should reach into any other directory.
  • src/config/
    • Polyfills and configuration/plumbing code that is bundled via webpack. The configuration code adds properties to window that make it easier to tell what environment the script is running in. This is useful because the code can be run in the content script, background, options page, or in the actual page when injected by Phabricator and each environment will have different ways to do different things.
  • src/e2e/
    • E2e test suite.
  • scripts/
    • Development scripts.
  • webpack
    • Build configs.
  • build
    • Generated directory containing the output from webpack and the generated bundles for each browser.

Requirements

  • node
  • yarn
  • make

Development

For each browser run:

yarn run dev

To only build for a single browser (which makes builds faster in local development), set the env var TARGETS=chrome or TARGETS=firefox.

Now, follow the steps below for the browser you intend to work with.

Chrome

  • Browse to chrome://extensions.
  • If you already have the Sourcegraph extension installed, disable it by unchecking the "Enabled" box.
  • Click on Load unpacked extensions, and select the build/chrome folder.
  • Browse to any public repository on GitHub to confirm it is working.
  • After making changes it is necessary to refresh the extension. This is done by going to chrome://extensions and clicking "Reload".

Add dist folder

Updating the bundle

Click reload for Sourcegraph at chrome://extensions

Firefox (hot reloading)

In a separate terminal session run:

yarn global add web-ext
yarn run dev:firefox

A Firefox window will be spun up with the extension already installed.

Updating the bundle

Save a file and wait for webpack to finish rebuilding.

Caveats

The window that is spun up is completely separate from any existing sessions you have on Firefox. You'll have to sign into everything at the beginning of each development session(each time you run yarn run dev:firefox). You should ensure you're signed into any Sourcegraph instance you point the extension at as well as GitHub.

Firefox (manual)

  • Go to about:debugging
  • Select "Enable add-on debugging"
  • Click "Load Temporary Add-on" and select "firefox-bundle.xpi"
  • More information

Updating the bundle

Click reload for Sourcegraph at about:debugging

Testing

  • Unit tests: yarn test
  • E2E tests: yarn test-e2e

e2e tests

The test suite in e2e/github.test.ts runs on the release branch bext/release in both Chrome and Firefox against a Sourcegraph Docker instance.

The test suite in e2e/phabricator.test.ts tests the Phabricator native integration. It assumes an existing Sourcegraph and Phabricator instance that has the Phabricator extension installed. There are automated scripts to set up the Phabricator instance, see https://docs.sourcegraph.com/dev/phabricator_gitolite. It currently does not run in CI and is intended to be run manually for release testing.

e2e/bitbucket.test.ts tests the browser extension on a Bitbucket Server instance.

e2e/gitlab.test.ts tests the browser extension on gitlab.com (or a private Gitlab instance).

Deploy

Deployment the Chrome web store happen automatically in CI when the bext/release branch is updated. Releases are also uploaded to the GitHub releases page and tagged in git.

To release the latest commit on master, ensure your master is up-to-date and run

git push origin master:bext/release