Skip to content

Commit

Permalink
fix(extension): Upgrade crxjs to 2.0 to add support for firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedBassem committed Aug 18, 2024
1 parent 99b24bc commit 485276e
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 87 deletions.
22 changes: 17 additions & 5 deletions .github/workflows/extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,24 @@ jobs:
- name: Setup
uses: ./tooling/github/setup

- name: Build the extension
- name: Build the extension (chrome)
working-directory: apps/browser-extension
run: pnpm run build
run: pnpm run build --outDir dist-chrome

- name: Upload Extension Archive
- name: Build the extension (firefox)
env:
VITE_BUILD_FIREFOX: true
working-directory: apps/browser-extension
run: pnpm run build --outDir dist-firefox

- name: Upload Extension Archive (chrome)
uses: actions/upload-artifact@v4
with:
name: hoarder-extension-chrome
path: apps/browser-extension/dist-chrome/*

- name: Upload Extension Archive (firefox)
uses: actions/upload-artifact@v4
with:
name: hoarder-extension
path: apps/browser-extension/dist/*
name: hoarder-extension-firefox
path: apps/browser-extension/dist-firefox/*
3 changes: 2 additions & 1 deletion apps/browser-extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"default_popup": "index.html"
},
"background": {
"service_worker": "src/background/background.ts"
"service_worker": "src/background/background.ts",
"scripts": ["src/background/background.ts"]
},
"options_ui": {
"page": "index.html#options",
Expand Down
2 changes: 1 addition & 1 deletion apps/browser-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"zod": "^3.22.4"
},
"devDependencies": {
"@crxjs/vite-plugin": "^1.0.14",
"@crxjs/vite-plugin": "2.0.0-beta.25",
"@hoarder/eslint-config": "workspace:^0.2.0",
"@hoarder/prettier-config": "workspace:^0.1.0",
"@hoarder/tailwind-config": "workspace:^0.1.0",
Expand Down
4 changes: 3 additions & 1 deletion apps/browser-extension/src/background/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ async function handleContextMenuClick(info: chrome.contextMenus.OnClickData) {
};
}
if (newBookmark) {
await chrome.storage.session.set({
chrome.storage.session.set({
[NEW_BOOKMARK_REQUEST_KEY_NAME]: newBookmark,
});
// NOTE: Firefox only allows opening context menus if it's triggered by a user action.
// awaiting on any promise before calling this function will lose the "user action" context.
await chrome.action.openPopup();
}
}
Expand Down
8 changes: 7 additions & 1 deletion apps/browser-extension/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,11 @@ import manifest from "./manifest.json";

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react(), crx({ manifest })],
plugins: [
react(),
crx({
manifest,
browser: process.env.VITE_BUILD_FIREFOX ? "firefox" : "chrome",
}),
],
});
121 changes: 43 additions & 78 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 485276e

Please sign in to comment.