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

Commit f5705f4

Browse files
committed
use latest browser.* manifest V3 APIs (fix firefox)
1 parent 5f40471 commit f5705f4

File tree

5 files changed

+24
-16
lines changed

5 files changed

+24
-16
lines changed

client/browser/scripts/tasks.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ function writeManifest(environment: BuildEnvironment, browser: Browser, writeDir
186186
delete manifest.storage
187187
}
188188

189+
if (browser === 'firefox') {
190+
// activeTab is not sufficient to call browser.scripting.executeScript (as it is in Chrome).
191+
manifest.permissions.push('scripting')
192+
}
193+
189194
if (browser === 'safari') {
190195
// If any modifications need to be done to the manifest for Safari, they
191196
// can be done here.
@@ -194,9 +199,12 @@ function writeManifest(environment: BuildEnvironment, browser: Browser, writeDir
194199
}
195200
}
196201

197-
// Add the inline extensions to web accessible resources
198-
manifest.web_accessible_resources = manifest.web_accessible_resources || []
199-
manifest.web_accessible_resources.push('extensions/*')
202+
// Firefox doesn't support service workers, so we need a workaround. See
203+
// https://github.com/mozilla/web-ext/issues/2532.
204+
if (browser === 'firefox') {
205+
manifest.background!.scripts = [manifest.background!.service_worker]
206+
delete manifest.background!.service_worker
207+
}
200208

201209
delete manifest.$schema
202210

client/browser/src/browser-extension/browser-action-icon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const browserActionIconPaths: Record<BrowserActionIconState, BrowserActionIconPa
6060
export function setBrowserActionIconState(iconState: BrowserActionIconState): void {
6161
const iconPaths = browserActionIconPaths[iconState]
6262
console.log('Setting icons to', iconPaths)
63-
browser.browserAction.setIcon({ path: iconPaths }).catch(error => {
63+
browser.action.setIcon({ path: iconPaths }).catch(error => {
6464
console.error(error)
6565
})
6666
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ async function main(): Promise<void> {
203203
* Loading content script dynamically
204204
* See https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Content_scripts#loading_content_scripts
205205
*/
206-
await browser.tabs.executeScript(tabId, {
207-
file: 'js/contentPage.main.bundle.js',
208-
runAt: 'document_end',
206+
await browser.scripting.executeScript({
207+
files: ['js/contentPage.main.bundle.js'],
208+
target: { tabId },
209209
})
210210
}
211211
})
@@ -281,7 +281,7 @@ async function main(): Promise<void> {
281281

282282
// The `popup=true` param is used by the options page to determine if it's
283283
// loaded in the popup or in th standalone options page.
284-
browser.browserAction.setPopup({ popup: 'options.html?popup=true' })
284+
browser.action.setPopup({ popup: 'options.html?popup=true' })
285285

286286
const ENDPOINT_KIND_REGEX = /^(proxy|expose)-/
287287

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Set globals first before any imports.
2-
import '../../config/extension.entry'
32
import '../../config/content.entry'
3+
import '../../config/extension.entry'
44
// Polyfill before other imports.
55
import '../../shared/polyfills'
66

77
import { firstValueFrom, fromEvent, Subscription } from 'rxjs'
88

9-
import { setLinkComponent, AnchorLink } from '@sourcegraph/wildcard'
9+
import { AnchorLink, setLinkComponent } from '@sourcegraph/wildcard'
1010

1111
import { determineCodeHost } from '../../shared/code-hosts/shared/codeHost'
1212
import { injectCodeIntelligence } from '../../shared/code-hosts/shared/inject'
@@ -46,7 +46,7 @@ function loadStyleSheet(options: { id: string; path: string }): HTMLLinkElement
4646
styleSheet.id = id
4747
styleSheet.rel = 'stylesheet'
4848
styleSheet.type = 'text/css'
49-
styleSheet.href = browser.extension.getURL(path)
49+
styleSheet.href = browser.runtime.getURL(path)
5050
}
5151
return styleSheet
5252
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ declare namespace browser.bookmarks {
133133
>
134134
}
135135

136-
declare namespace browser.browserAction {
136+
declare namespace browser.action {
137137
type ColorArray = [number, number, number, number]
138138
type ImageDataType = ImageData
139139

@@ -1361,6 +1361,10 @@ declare namespace browser.storage {
13611361
const onChanged: CallbackEventEmitter<(changes: ChangeDict<any>, areaName: AreaName) => void>
13621362
}
13631363

1364+
declare namespace browser.scripting {
1365+
function executeScript(details: { files: string[], target: any }): Promise<object[]>
1366+
}
1367+
13641368
declare namespace browser.tabs {
13651369
type MutedInfoReason = 'capture' | 'extension' | 'user'
13661370
interface MutedInfo {
@@ -1425,10 +1429,6 @@ declare namespace browser.tabs {
14251429
function captureVisibleTab(windowId?: number, options?: extensionTypes.ImageDetails): Promise<string>
14261430
function detectLanguage(tabId?: number): Promise<string>
14271431
function duplicate(tabId: number): Promise<Tab>
1428-
function executeScript(
1429-
tabId: number | undefined,
1430-
details: extensionTypes.InjectDetails
1431-
): Promise<object[]>
14321432
function get(tabId: number): Promise<Tab>
14331433
// deprecated: function getAllInWindow(): x;
14341434
function getCurrent(): Promise<Tab>

0 commit comments

Comments
 (0)