Skip to content

Commit 57c19aa

Browse files
committed
Add webextension-polyfill
Add webextension-polyfill [1]. This polyfill allows using the standard Promise-based WebExtension API on Google Chrome. [1] https://github.com/mozilla/webextension-polyfill
1 parent 08890f1 commit 57c19aa

28 files changed

+603
-264
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
55

66
## [Unreleased]
7+
### Added
8+
- Add webextension-polyfill.
79

810
## [1.2.0] - 2021-09-18
911
### Added

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ npm install
7171
- [ESLint](https://eslint.org/): Static analyzer.
7272
- [Prettier](https://prettier.io/): Code formatter.
7373
- [web-ext](https://github.com/mozilla/web-ext): Command line tool for web extensions.
74+
- [webextension-polyfill](https://github.com/mozilla/webextension-polyfill): WebExtension `browser` API polyfill.
7475

7576
#### Testing
7677
- [Jest](https://jestjs.io/): Testing framework.

attributions.txt

Lines changed: 378 additions & 0 deletions
Large diffs are not rendered by default.

package-lock.json

Lines changed: 18 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
"@testing-library/user-event": "^13.2.1",
3737
"@tsconfig/svelte": "^2.0.1",
3838
"@types/faker": "^5.5.8",
39-
"@types/firefox-webext-browser": "^82.0.1",
4039
"@types/jest": "^27.0.1",
4140
"@types/lodash-es": "^4.17.5",
41+
"@types/webextension-polyfill": "^0.8.0",
4242
"@typescript-eslint/eslint-plugin": "^4.31.0",
4343
"@typescript-eslint/parser": "^4.31.0",
4444
"babel-jest": "^27.1.1",
@@ -47,11 +47,10 @@
4747
"eslint-plugin-simple-import-sort": "^7.0.0",
4848
"eslint-plugin-svelte3": "^3.2.1",
4949
"faker": "^5.5.3",
50-
"install": "^0.13.0",
5150
"jest": "^27.1.1",
5251
"lodash-es": "^4.17.21",
53-
"mockzilla": "^0.9.0",
54-
"mockzilla-webextension": "^0.9.0",
52+
"mockzilla": "^0.12.0",
53+
"mockzilla-webextension": "^0.13.0",
5554
"normalize.css": "^8.0.1",
5655
"postcss": "^8.3.6",
5756
"postcss-url": "^10.1.3",
@@ -70,7 +69,7 @@
7069
"ts-jest": "^27.0.5",
7170
"tslib": "^2.3.1",
7271
"typescript": "^4.1.6",
73-
"webextension-polyfill-ts": "^0.26.0"
72+
"webextension-polyfill": "^0.8.0"
7473
},
7574
"dependencies": {},
7675
"webExt": {

rollup.config.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ export default [{
6666
title: 'Treetop'
6767
}),
6868
],
69-
external: ['firefox-webext-browser']
7069
}, {
7170
input: 'src/options/main.ts',
7271
output: {
@@ -159,5 +158,4 @@ export default [{
159158
verbose: true
160159
})
161160
],
162-
external: ['firefox-webext-browser']
163161
}];

src/background_script/init.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { browser } from 'webextension-polyfill-ts';
1+
import browser from 'webextension-polyfill';
22

33
import { createContextMenus } from './menus';
44
import { openTreetop, openWelcome } from './open';

src/background_script/menus.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { browser } from 'webextension-polyfill-ts';
1+
import browser, { Menus } from 'webextension-polyfill';
22

33
/**
44
* Create context menus.
@@ -9,7 +9,7 @@ export const createContextMenus = (): void => {
99
const origin = browser.runtime.getURL('');
1010

1111
const commonMenuParams: {
12-
contexts: browser.menus.ContextType[];
12+
contexts: Menus.ContextType[];
1313
documentUrlPatterns: string[];
1414
} = {
1515
contexts: ['link'],

src/background_script/open.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { browser } from 'webextension-polyfill-ts';
1+
import browser, { Action, Runtime, Tabs } from 'webextension-polyfill';
22

33
/**
44
* Open the welcome page when the extension is installed.
55
*/
66
export const openWelcome = ({
77
reason,
88
temporary,
9-
}: browser.runtime._OnInstalledDetails): void => {
9+
}: Runtime.OnInstalledDetailsType): void => {
1010
if (temporary || reason !== 'install') {
1111
return;
1212
}
@@ -29,15 +29,15 @@ export const openWelcome = ({
2929
* Shift: Open in new tab
3030
*/
3131
export const openTreetop = (
32-
_tab: browser.tabs.Tab,
33-
info: browser.browserAction.OnClickData | undefined
32+
_tab: Tabs.Tab,
33+
info: Action.OnClickData | undefined
3434
): void => {
3535
if (!info) {
3636
return;
3737
}
3838

3939
const url = browser.runtime.getURL('treetop.html');
40-
const params: browser.tabs._CreateCreateProperties = { url };
40+
const params: Tabs.CreateCreatePropertiesType = { url };
4141

4242
const ctrl =
4343
info.modifiers.includes('Ctrl') || info.modifiers.includes('Command');

src/background_script/options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { browser } from 'webextension-polyfill-ts';
1+
import browser from 'webextension-polyfill';
22

33
/**
44
* Set default options.

0 commit comments

Comments
 (0)