Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 8fb7f19

Browse files
committed
upgrade browser extension to manifest v3
Chrome's and the Chrome Web Store's push for [Manifest V3](https://developer.chrome.com/docs/extensions/develop/migrate) means that our browser extension will start to be unusable in a few months unless we upgrade to Manifest V3. - Removes "Enable Sourcegraph on this domain" context menu item that didn't seem to work. We were adding this ourselves (using `webext-domain-permission-toggle`), and it didn't seem to work. Our options popup shows a permission request, which is sufficient. - Otherwise preserves all existing functionality as best I could tell. Test plan: 1. Confirm that the browser extension continues to inject the Sourcegraph icon on https://github.com/hashicorp/errwrap. 1. Load up https://gitlab.com/sqs/web in my local dev Sourcegraph instance and confirm that the browser extension injects the Sourcegraph icon on https://gitlab.com/sqs/web code files.
1 parent 341bfe7 commit 8fb7f19

File tree

7 files changed

+83
-78
lines changed

7 files changed

+83
-78
lines changed

client/browser/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ ts_project(
262262
"//:node_modules/utility-types",
263263
"//:node_modules/uuid",
264264
"//:node_modules/vitest",
265-
"//:node_modules/webext-domain-permission-toggle",
266265
"//:node_modules/webextension-polyfill", #keep
267266
],
268267
)
Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,58 @@
11
{
2-
"$schema": "http://json.schemastore.org/webextension",
2+
"$schema": "https://json.schemastore.org/chrome-manifest",
33
"version": "0.0.0",
44
"name": "Sourcegraph",
5-
"manifest_version": 2,
5+
"manifest_version": 3,
66
"description": "Adds code intelligence to GitHub, GitLab, and other hosts: hovers, definitions, references. For 20+ languages.",
7-
"browser_action": {
7+
"action": {
88
"default_title": "Sourcegraph",
99
"default_icon": {
1010
"32": "img/icon-32.png",
1111
"48": "img/icon-48.png",
1212
"128": "img/icon-128.png"
13-
}
13+
},
14+
"default_popup": "options.html"
1415
},
1516
"icons": {
1617
"32": "img/icon-32.png",
1718
"48": "img/icon-48.png",
1819
"128": "img/icon-128.png"
1920
},
2021
"background": {
21-
"scripts": ["js/backgroundPage.main.bundle.js"]
22+
"service_worker": "js/backgroundPage.main.bundle.js"
2223
},
24+
"content_scripts": [
25+
{
26+
"matches": ["https://github.com/*"],
27+
"js": ["js/contentPage.main.bundle.js"],
28+
"run_at": "document_idle"
29+
}
30+
],
31+
"permissions": ["activeTab", "storage"],
32+
"host_permissions": ["https://github.com/*", "https://sourcegraph.com/*"],
33+
"optional_host_permissions": ["https://*/*", "http://*/*"],
2334
"options_ui": {
2435
"page": "options.html",
2536
"open_in_tab": true
2637
},
2738
"storage": {
2839
"managed_schema": "schema.json"
2940
},
30-
"optional_permissions": ["tabs", "http://*/*", "https://*/*"],
31-
"content_security_policy": "script-src 'self' blob:; object-src 'self'",
32-
"web_accessible_resources": ["img/*", "css/*"],
41+
"web_accessible_resources": [
42+
{
43+
"resources": ["img/*", "css/*"],
44+
"matches": ["<all_urls>"]
45+
}
46+
],
3347
"omnibox": {
3448
"keyword": "src"
3549
},
36-
"applications": {
50+
"browser_specific_settings": {
3751
"gecko": {
3852
"id": "sourcegraph-for-firefox@sourcegraph.com"
3953
}
4054
},
4155
"dev": {
42-
"permissions": [
43-
"storage",
44-
"activeTab",
45-
"contextMenus",
46-
"https://github.com/*",
47-
"https://gitlab.com/*",
48-
"https://localhost:3443/*",
49-
"https://sourcegraph.com/*",
50-
"http://localhost:32773/*"
51-
],
5256
"key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCl2X/axNHMbP0K/NCpMzGo/pgBSsHB2xKx6tfohORKtEv2wUMBPmkK3++kirrwYO2f8Ficyq6pjlXV8LjwPSjSw9KZj6bkDn8QNoSdCp6x9i8ZOWPw6UTQ6s54b3rGQNyvrvfD7S6LphxGEx8rNlkjpWKcrvY3+DyoFKHP/hax7wIDAQAB"
53-
},
54-
"prod": {
55-
"permissions": ["activeTab", "storage", "contextMenus", "https://github.com/*", "https://sourcegraph.com/*"]
5657
}
5758
}

client/browser/src/browser-extension/scripts/backgroundPage.main.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
catchError,
1919
distinctUntilChanged,
2020
} from 'rxjs/operators'
21-
import addDomainPermissionToggle from 'webext-domain-permission-toggle'
2221

2322
import { isDefined, fetchCache } from '@sourcegraph/common'
2423
import { type GraphQLResult, requestGraphQLCommon } from '@sourcegraph/http-client'
@@ -293,9 +292,6 @@ async function main(): Promise<void> {
293292
// loaded in the popup or in th standalone options page.
294293
browser.browserAction.setPopup({ popup: 'options.html?popup=true' })
295294

296-
// Add "Enable Sourcegraph on this domain" context menu item
297-
addDomainPermissionToggle()
298-
299295
const ENDPOINT_KIND_REGEX = /^(proxy|expose)-/
300296

301297
const portKind = (port: browser.runtime.Port): string | undefined => {

client/browser/src/types/webextension-polyfill/index.d.ts

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,10 @@ declare namespace browser.browserAction {
162162
function openPopup(): Promise<void>
163163
function setBadgeText(details: { text: string | null; tabId?: number }): void
164164
function getBadgeText(details: { tabId?: number }): Promise<string>
165-
function setBadgeBackgroundColor(details: { color: string | ColorArray | null; tabId?: number }): void
165+
function setBadgeBackgroundColor(details: {
166+
color: string | ColorArray | null
167+
tabId?: number
168+
}): void
166169
function getBadgeBackgroundColor(details: { tabId?: number }): Promise<ColorArray>
167170

168171
interface SetBadgeTextColorDetails {
@@ -176,12 +179,10 @@ declare namespace browser.browserAction {
176179
}
177180
function setBadgeTextColor(details: SetBadgeTextColorDetails & { tabId?: number }): void
178181
// a union type would allow specifying both, which is not allowed.
179-
// eslint-disable-next-line @typescript-eslint/unified-signatures
180182
function setBadgeTextColor(details: SetBadgeTextColorDetails & { windowId?: number }): void
181183

182184
function getBadgeTextColor(details: { tabId?: string }): Promise<ColorArray>
183185
// a union type would allow specifying both, which is not allowed.
184-
// eslint-disable-next-line @typescript-eslint/unified-signatures
185186
function getBadgeTextColor(details: { windowId?: string }): Promise<ColorArray>
186187

187188
function enable(tabId?: number): void
@@ -342,7 +343,11 @@ declare namespace browser.contextualIdentities {
342343
name: string
343344
}
344345

345-
function create(details: { name: string; color: IdentityColor; icon: IdentityIcon }): Promise<ContextualIdentity>
346+
function create(details: {
347+
name: string
348+
color: IdentityColor
349+
icon: IdentityIcon
350+
}): Promise<ContextualIdentity>
346351
function get(cookieStoreId: string): Promise<ContextualIdentity | null>
347352
function query(details: { name?: string }): Promise<ContextualIdentity[]>
348353
function update(
@@ -424,13 +429,19 @@ declare namespace browser.contentScripts {
424429
unregister: () => void
425430
}
426431

427-
function register(contentScriptOptions: RegisteredContentScriptOptions): Promise<RegisteredContentScript>
432+
function register(
433+
contentScriptOptions: RegisteredContentScriptOptions
434+
): Promise<RegisteredContentScript>
428435
}
429436

430437
declare namespace browser.devtools.inspectedWindow {
431438
const tabId: number
432439

433-
function reload(reloadOptions?: { ignoreCache?: boolean; userAgent?: string; injectedScript?: string }): void
440+
function reload(reloadOptions?: {
441+
ignoreCache?: boolean
442+
userAgent?: string
443+
injectedScript?: string
444+
}): void
434445
}
435446

436447
declare namespace browser.devtools.network {
@@ -690,7 +701,10 @@ declare namespace browser.history {
690701

691702
function deleteUrl(details: { url: string }): Promise<void>
692703

693-
function deleteRange(range: { startTime: number | string | Date; endTime: number | string | Date }): Promise<void>
704+
function deleteRange(range: {
705+
startTime: number | string | Date
706+
endTime: number | string | Date
707+
}): Promise<void>
694708

695709
function deleteAll(): Promise<void>
696710

@@ -787,8 +801,12 @@ declare namespace browser.omnibox {
787801
function setDefaultSuggestion(suggestion: { description: string }): void
788802

789803
const onInputStarted: EventEmitter<void>
790-
const onInputChanged: CallbackEventEmitter<(text: string, suggest: (arg: SuggestResult[]) => void) => void>
791-
const onInputEntered: CallbackEventEmitter<(text: string, disposition: OnInputEnteredDisposition) => void>
804+
const onInputChanged: CallbackEventEmitter<
805+
(text: string, suggest: (arg: SuggestResult[]) => void) => void
806+
>
807+
const onInputEntered: CallbackEventEmitter<
808+
(text: string, disposition: OnInputEnteredDisposition) => void
809+
>
792810
const onInputCancelled: EventEmitter<void>
793811
}
794812

@@ -803,7 +821,11 @@ declare namespace browser.pageAction {
803821

804822
function getTitle(details: { tabId: number }): Promise<string>
805823

806-
function setIcon(details: { tabId: number; path?: string | object; imageData?: ImageDataType }): Promise<void>
824+
function setIcon(details: {
825+
tabId: number
826+
path?: string | object
827+
imageData?: ImageDataType
828+
}): Promise<void>
807829

808830
function setPopup(details: { tabId: number; popup: string }): void
809831

@@ -1403,7 +1425,10 @@ declare namespace browser.tabs {
14031425
function captureVisibleTab(windowId?: number, options?: extensionTypes.ImageDetails): Promise<string>
14041426
function detectLanguage(tabId?: number): Promise<string>
14051427
function duplicate(tabId: number): Promise<Tab>
1406-
function executeScript(tabId: number | undefined, details: extensionTypes.InjectDetails): Promise<object[]>
1428+
function executeScript(
1429+
tabId: number | undefined,
1430+
details: extensionTypes.InjectDetails
1431+
): Promise<object[]>
14071432
function get(tabId: number): Promise<Tab>
14081433
// deprecated: function getAllInWindow(): x;
14091434
function getCurrent(): Promise<Tab>
@@ -1415,7 +1440,10 @@ declare namespace browser.tabs {
14151440
// windowId?: number,
14161441
// tabs: number[]|number,
14171442
// }): Promise<browser.windows.Window>;
1418-
function insertCSS(tabId: number | undefined, details: extensionTypes.InjectDetailsCSS): Promise<void>
1443+
function insertCSS(
1444+
tabId: number | undefined,
1445+
details: extensionTypes.InjectDetailsCSS
1446+
): Promise<void>
14191447
function removeCSS(tabId: number | undefined, details: extensionTypes.InjectDetails): Promise<void>
14201448
function move(
14211449
tabIds: number | number[],
@@ -1930,7 +1958,10 @@ declare namespace browser.windows {
19301958

19311959
function getCurrent(getInfo?: { populate?: boolean; windowTypes?: WindowType[] }): Promise<Window>
19321960

1933-
function getLastFocused(getInfo?: { populate?: boolean; windowTypes?: WindowType[] }): Promise<Window>
1961+
function getLastFocused(getInfo?: {
1962+
populate?: boolean
1963+
windowTypes?: WindowType[]
1964+
}): Promise<Window>
19341965

19351966
function getAll(getInfo?: { populate?: boolean; windowTypes?: WindowType[] }): Promise<Window[]>
19361967

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,6 @@
427427
"utility-types": "^3.10.0",
428428
"uuid": "^8.3.0",
429429
"vscode-uri": "^3.0.7",
430-
"webext-domain-permission-toggle": "^1.0.1",
431430
"webextension-polyfill": "^0.6.0",
432431
"whatwg-url": "^14.0.0",
433432
"yaml-ast-parser": "^0.0.43",

0 commit comments

Comments
 (0)